Correction status:qualified
Teacher's comments:完成的不错,还没教你就会了。
<?php header("Content-type: text/html; charset=utf-8"); // 定义数组 $a =[]; $b=array(); //关联数组 echo'<pre>'; $c =["name"=>"小虫子","sex"=>"男","age"=>12]; print_r($c); echo '<hr>'; //索引数组 $d=["小虫子","男",18]; print_r($d); echo '<hr>'; // 二位数组 $f= [["name"=>"小虫子","sex"=>"男","age"=>12],["name"=>"大虫子","sex"=>"男","age"=>15]]; print_r($f); echo '<hr>'; // 循环二维数组 echo '<h1>循环二维数组</h1><br>'; foreach($f as $ff) { foreach($ff as $fff) { print_r($fff); echo '<hr>'; } } $f= [["name"=>"小虫子","sex"=>"男","age"=>12,"媳妇"=>["小花","小婷","小倩"]],["name"=>"大虫子","sex"=>"男","age"=>15,"媳妇"=>["小花","小婷","小倩"]]]; echo '<h1>循环三维数组</h1><br>'; foreach($f as $ff) { echo "姓名:{$ff['name']} <br>"; foreach($ff as $key=>$fff) { if($key=="媳妇") { foreach($fff as $key2=>$ffff) { $key3 = $key2+1; echo "<strong style=\"color:red;font-size:2rem;\">媳妇{$key3}:{$ffff} <br></strong>"; } } } echo '<hr>'; }
点击 "运行实例" 按钮查看在线实例