创建一个二维数组,进行遍历
<?php //一维数组 $fruits=['苹果','香蕉','桃儿','梨','草莓','西瓜']; //二维数组 $foods=[ ['苹果','香蕉','桃儿','梨','草莓','西瓜'], ['豆角','茄子','辣椒','西红柿','白菜','萝卜'], ['馒头','米饭','包子','烧饼','小米粥'] ]; //遍历一维数组 foreach ($fruits as $fruit){ echo $fruit; echo '<br>'; } echo '<hr>'; //遍历二维数组 foreach ($foods as $food){ foreach ($food as $value){ echo $value; echo '<br>'; } }
点击 "运行实例" 按钮查看在线实例