Correction status:qualified
Teacher's comments:完成的不错。
<?php // 索引数组 echo '<h2>索引数组</h2>'; $arr = ['张三', '李四', '王二']; echo '<pre>'; print_r($arr); echo '<hr>'; foreach ($arr as $k => $v) { echo $k . '->' . $v . '<br>'; } echo '<hr>'; // 关联数组 echo '<h2>关联数组</h2>'; $arr = ['zhangsan' => '张三', 'lisi' => '李四', 'wanger' => '王二']; print_r($arr); echo '<hr>'; foreach ($arr as $k => $v) { echo $k . '->' . $v . '<br>'; } echo '<hr>'; // 二维索引数组 echo '<h2>二维索引数组</h2>'; $arr = [ ['name' => '张三', 'age' => '18'], ['name' => '李四', 'age' => '25'], ['name' => '王二', 'age' => '16'], ]; print_r($arr); echo '<hr>'; foreach ($arr as $k => $v) { echo $k . '->' . $v['name'] . '<br>'; } // 二维关联数组 echo '<h2>二维关联数组</h2>'; $arr = [ 'zhangsan' => ['name' => '张三', 'age' => '18'], 'lisi' => ['name' => '李四', 'age' => '25'], 'wanger' => ['name' => '王二', 'age' => '16'], ]; print_r($arr); echo '<hr>'; foreach ($arr as $k => $v) { foreach ($v as $k1 => $v1) { echo $k . '->' . $k1 . '->' . $v1 . '<br>'; } } echo '<hr>'; //三维混合数组 echo '<h2>三维数组</h2>'; $arr = [ ['name' => '张三', 'age' => '18', 'skill' => ['唱', '跳', '篮球', 'Rap']], ['name' => '李四', 'age' => '25', 'skill' => ['唱', '跳', '篮球', 'Rap']], ['name' => '王二', 'age' => '16', 'skill' => ['唱', '跳', '篮球', 'Rap']], ]; print_r($arr); echo '<hr>'; foreach ($arr as $k => $v) { foreach ($v as $k1 => $v1) { if (is_array($v1)) { foreach ($v1 as $k2 => $v2) { echo $k . '->' . $k1 . '->' . $k2 . '->' . $v2 . '<br>'; } } else { echo $k . '->' . $k1 . '->' . $v1 . '<br>'; } } };
点击 "运行实例" 按钮查看在线实例
练习了几遍,运行不报错,简单的提交了