0

我有以下代码。在最后一个 foreach 中,我想在数组中添加$last_array$last2_array作为键/值对。$display这是我尝试过的:

$display[] = array($last_array => $last2_array); //doesn't work
print_r($display); //under the loop prints nothing

编码:

$display=array();//declare the array outside the loop
foreach ($array as $arrays){ 
    foreach ($arrays as $elem) {
        unset($elem['id']); //Removes id key
        unset($elem['idno']); //Removes idno key
        foreach ($elem as $last_array => $last2_array) {
            //code here                       
            #echo $last_array. ": ".$last2_array."<br>";//This prints data, it's not empty.
        }       
        echo "<br>";
    }
}

提前致谢。

4

2 回答 2

1
$display=array();//declare the array outside the loop
foreach ($array as $arrays){ 
    foreach ($arrays as $elem) {
        unset($elem['id']); //Removes id key
        unset($elem['idno']); //Removes idno key
        foreach ($elem as $last_array => $last2_array) {
          $display[$last_array] = $last2_array;
        }       
    }
}
于 2013-06-17T22:32:37.807 回答
0

我建议您搜索多维数组,以了解有关创建和访问它们的更多信息。

$object_id=$array['results'][0]['object_id'];
$display_label=$array['results'][0]['display_label'];

$display = array($object_id => $display_label);
print_r($display);
于 2013-06-17T23:19:00.037 回答