请问next()
和prev()
对关联数组有效吗?关联数组指针/遍历关联数组
我想遍历数据集,如果你愿意的话,它将使用两条记录来描述一个“游戏”。所以当我登录第二张唱片时,我需要先查看唱片并抓取eg_item['final_score']
。
{"id":"75", "team_name":"TEAM1", "home_team_name":"TEAM1", "image":"TEAM1_HOME.png", "final_score":"37"},
{"id":"75", "team_name":"TEAM2", "home_team_name":"TEAM2", "image":"TEAM2_AWAY.png", "final_score":"10"},
{"id":"76", "team_name":"TEAM1", "home_team_name":"TEAM1", "image":"TEAM1_HOME.png", "final_score":"10"},
{"id":"76", "team_name":"TEAM2", "home_team_name":"TEAM2", "image":"TEAM2_AWAY.png", "final_score":"14"},
所有的我发现使用跛脚array('one','two',three')
类型的例子,只是不帮助的例子。
代码示例:
foreach($json_output as $eg_item) :
if($this_game_id == $last_game_id) :
// get this records info
$b_score = $eg_item['final_score'];
$b_team_name = $eg_item['team_name'];
prev($json_output);
// get previous records info
$a_score = $eg_item['final_score'];
$a_team_name = $eg_item['team_name'];
$a_game_id = $eg_item['id'];
// put pointer back
next($json_output);
else :
// skip next record
endif;
endforeach;
是的,他们在assoc命令数组。你能显示一些代码吗? – netcoder 2011-02-10 16:28:10