Help w/ associative array merge
greetings. i'm trying to create a new array w/ all the fixins from an old array. my feed looks like:
{"id":"75", "team_name":"team1", "home_team_name":"team1", "image":"team1_HOME.png", "final_score":"37"}, {"id":"75", "team_name":"team2", "home_team_name":"team1", "image":"team2_AWAY.png", "final_score":"10"},
so each game has to records associated with it, how can i开发者_如何转开发 pick and choose data to place in a new array so i get an array like:
{"id":"75", "team_name":"team1", "home_team_name":"team2", "image_home":"team1_HOME.png", "image_visitor":"team2_AWAY.png", "final_score_1":"37", "final_score_2":"99"},
i've tried using next() and continue; to no avail...
__ * update:
they keep two records for each game, one for each score and some 'meta' about the team. i need to grab both records by matching id and run some logic on it to find out who the home team is, who the visiting team is, home score, visiting score. loop through and list.
is the best method creating a new array if the ids match?
or is there a way that i can just check the next records id while i'm in the current record for a match, if so run some logic?
thanks,
Try array_push, it will add to the end of an array. Also, "75" should be 75 since you're usually handling numerals as ID's.
It's good practice but not required.
well i ended up not merging the two items into one and just traversing by two and looking back at the prev() record like so:
for( $i = 1; $i < count( $json_output ); $i += 2 ) :
$current = $json_output[$i];
$last = $json_output[$i-1];
$item_from_last_array = $last['item_name'];
$item_from_this_array = $current['item_name'];
endfor;
精彩评论