Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:才写到这里呀, 太慢了
<?php // 数组创建 $arr = array(); $arr1 = []; // 索引数组 $arr = [ '孙尚香', '猴子', '安其拉' ]; // 关联数组 $arr = [ 'sunshangxiang' => '孙尚香', 'houzi' => '猴子', 'anqila' => '安其拉' ]; // ****多维数组***** // 二维数组 $arr1 = [ [ 'name' => '孙尚香', 'zhiye' => '射手' ], [ 'name' => '猴子', 'zhiye' => '打野' ], [ 'name' => '安其拉', 'zhiye' => '法师' ] ]; // 二维数组循环 foreach($arr1 as $k => $v){ echo $v['name'] .'=='. $v['zhiye']; echo '<hr>'; } // 三维数组 $arr2 = [ [ 'name' => '孙尚香', 'zhiye' => '射手', 'jineng' => [ '活力迸发', '翻滚突袭', '红莲爆弹', '究极弩***' ] ], [ 'name' => '猴子', 'zhiye' => '打野', 'jineng' => [ '活力迸发', '翻滚突袭', '红莲爆弹', '究极弩***' ] ], [ 'name' => '安其拉', 'zhiye' => '法师', 'jineng' => [ '活力迸发', '翻滚突袭', '红莲爆弹', '究极弩***' ] ] ]; // 三维数组循环 foreach($arr2 as $v){ echo '姓名:'. $v['name']; echo '<br>'; echo '职业:'. $v['zhiye']; echo '<br>'; echo '技能:'; foreach($v['jineng'] as $k => $vv){ echo $vv.'-'; } echo '<hr>' ; }
点击 "运行实例" 按钮查看在线实例
总结:学习了数组的创建,二维数组,三维数组,foreach循环