猿问

如图,关于PHP多维数组该怎么去遍历它?

当年话下
浏览 117回答 2
2回答

慕雪6442864

查询出来的数组就是$a = array(array(1,"苹果",1,"5元"),array(1,"苹果",1,"5元"),array(1,"苹果",1,"5元"));$b = array(array(1,"白菜",2,"3元"),array(1,"白菜",2,"3元"));分别查询 $a 和 $b 后,用 $data = array('水果'=>$a,'蔬菜'=>$b) 就可以实现

忽然笑

<?php$arr = ['a','b',['c','d']];foreach($arr as $i){if(is_array($i)){foreach($i as $j){echo $j;}} else {echo $i;}}用is_array()函数判断当前从数组中取到的元素是不是数组,如果是数组,就再加一层循环
随时随地看视频慕课网APP
我要回答