我很迷茫,在下面的代码中:
while($row = mysqli_fetch_object($result)){
$similar_games[$row->game_id]['id'][] = $row->id;
$similar_games[$row->game_id]['name'][] = $row->name;
$similar_games[$row->game_id][$type] = 0;
}
foreach($similar_games as $originalGameKey => $originalGame){
//Can be a case where union gets unset, and not populated. scares ksort();
$union = array();
$similar_values = array();
$union = $similar_concepts;
foreach($originalGame['id'] as $similarGameKey => $similarGame){
if(!isset($union[$similarGame])){
$union[] = $similarGame;
}
}
foreach($originalGame['id'] as $similarGameKey => $similarGame){
if(isset($union[$similarGame])){
$similar_values[] = $similarGame;
}
}
$similar_games[$originalGameKey]["union"] = $similar_values;
}
在这条线上$similar_values[] = $similarGame;
我试图得到$row->name
而不是$row->id
但我不知道如何使基于 ['id'] 的 foreach 访问 ['name'] 值。
如果这太令人困惑,我可以尝试澄清,但我自己在这里遇到了麻烦。