我有以下代码。在最后一个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>";
}
}
提前致谢。
答案 0 :(得分: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;
}
}
}
答案 1 :(得分:0)
我建议您搜索多维数组,以了解有关创建和访问它们的更多信息。
$object_id=$array['results'][0]['object_id'];
$display_label=$array['results'][0]['display_label'];
$display = array($object_id => $display_label);
print_r($display);