实例
<?php //关联数组 $arr1=array( 'name'=>'张三', 'age'=>25, 'sex'=>'男', 'address'=>'山东' ); //索引数组 $arr2=[5,8,9,20,3]; //循环输出数组 foreach($arr1 as $v){ echo $v."<br>"; } //二维数组 $arr3=[ ['西游记','吴承恩'], ['红楼梦','曹雪芹'], ['三国演义','罗贯中'], ['水浒传','施耐庵'] ]; echo "<hr>"; //循环输出二维数组 foreach($arr3 as $v){ foreach ($v as $vv) { echo $vv; } echo "<br>"; } echo '<hr>'; //三维数组 $arr4=[ [ 'name'=>'四大名著', 'count'=>['西游记','红楼梦','三国演义','水浒传'] ], [ 'name'=>'四大发明', 'count'=> ['指南针','火***','造纸术','印刷术'] ], ]; //循环输出三维数组 foreach($arr4 as $value){ echo $value['name'].'<br>'; foreach($value['count'] as $v){ echo $v.'<br>'; } }
运行实例 »
点击 "运行实例" 按钮查看在线实例
最后运行效果图: