首页 > 代码库 > foreach遍历 < 创建表 >练习题
foreach遍历 < 创建表 >练习题
原表如下:
效果图如下:
$attr = array(
array(
"code1"=>"p001","name1"=>"胡军","sex1"=>1,"nation1"=>"n003","birthday1"=>"1985-08-09"),
array(
"code1"=>"p002","name1"=>"周丹","sex1"=>0,"nation1"=>"n001","birthday1"=>"1984-04-17"),
array(
"code1"=>"p003","name1"=>"吴倩","sex1"=>0,"nation1"=>"n004","birthday1"=>"1981-10-29"),
array(
"code1"=>"p004","name1"=>"唐默","sex1"=>1,"nation1"=>"n001","birthday1"=>"1983-02-25")
);
?>
<table id="table" cellpadding="1" cellspacing="1" border="1">
<tr><th>code</th><th>name</th><th>sex</th><th>nation</th><th>birthday</th></tr>
<?php
foreach($attr as $k=>$v)
{
echo"<tr>";
echo"<td>".$v[‘code1‘]."</td>";
echo"<td>".$v[‘name1‘]."</td>";
echo"<td>".$v[‘sex1‘]."</td>";
echo"<td>".$v[‘nation1‘]."</td>";
echo"<td>".$v[‘birthday1‘]."</td>";
echo"</tr>";
}
?>
</table>
foreach遍历 < 创建表 >练习题