在php中遍歷二維數據的方法
1.使用for循環遍歷二維數據
$arr2=array(array("張三","20","男"),array("李四","25","男"),array("王五","19","女"),array("趙六","25","女"));
echo "<table border=2 bordercolor=red><tr><td>姓名</td><td>年齡</td& gt;<td>性別</td></tr>";
for($i=0;$i<4;$i++){
echo "<tr>";
for($j=0;$j<3;$j++){
echo "<td>";
echo $arr2[$i][$j];
echo "</td>";
}
echo "</tr>";
echo "<br>";
}
echo "</table>";
2.使用foreach循環遍歷二維數據
$arr = array('one'=>array('name'=>'張三','age'=>'23','sex'=>'男'),'two'=>array('name'=>'李四','age'=>'43','sex'=>'女'),
'three'=>array('name'=>'王五','age'=>'32','sex'=>'男'),
'four'=>array('name'=>'趙六','age'=>'12','sex'=>'女'));
foreach($arr as $k=>$val){
echo $val['name'].$val['age'].$val['sex']."<br>";
}
echo "<p>";