[英]how to display values of a multidimensional associative array using foreach loop
[英]Display multidimensional array using foreach and for loop
for(int $i=0; $i<count($lists["item_collection"]["entries"]); $i++){
foreach($lists['item_collection']['entries'] as $list)
{
$print['file_name'] = $list[$i]['name'];
$print['file_id'] = $list[$i]['id'];
$print['file_type'] = $list[$i]['type'];
array_push($content,$print);
}
}
我试图获取文件数组的名称,类型,ID,但我只得到第一个,所以我尝试对其进行循环,但它不起作用。 我这样做对吗?
我没有测试
foreach($lists["item_collection"]["entries"] as $v){
foreach($v as $val){
$print['file_name'] = $val['name'];
$print['file_id'] = $val['id'];
$print['file_type'] = $val['type'];
array_push($content,$print);
}
}
无需在for循环内执行此操作,只需:
foreach($lists["item_collection"]["entries"] as $key => $val){
$print['file_name'] = $val['name'];
$print['file_id'] = $val['id'];
$print['file_type'] = $val['type'];
array_push($content,$print);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.