最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

关于二维数组。解决办法

来源:http://erdangjiade.com/topic/79779.html 你好,世界。 2017-10-04 21:03浏览(0)

关于二维数组。
<?php
$group1 = array(
("name"=>"zs","age"=>"10","sex"=>"nan"),
("name"=>"zs","age"=>"10","sex"=>"nan"),
("name"=>"zs","age"=>"10","sex"=>"nan"),
("name"=>"ls","age"=>"11","sex"=>"nan"),
("name"=>"ww","age"=>"12","sex"=>"nv"),
("name"=>"ls","age"=>"11","sex"=>"nan"),
("name"=>"ww","age"=>"12","sex"=>"nv"),
("name"=>"ls","age"=>"11","sex"=>"nan"),
("name"=>"ww","age"=>"12","sex"=>"nv")
);

echo '<table border="1" width="800" align>';
echo '<caption><h1>数组转化为表格</h1><caption>';

foreach( $group as $row ){
echo '<tr>';
foreach( $row as $col ){
echo '<td>{$col}</td>';
}
echo '</tr>';
}
echo '</table>';
?>


这样写为何不对?
------解决方案--------------------
	$group = array(
array("name"=>"zs","age"=>"10","sex"=>"nan"),
array("name"=>"zs","age"=>"10","sex"=>"nan"),
array("name"=>"zs","age"=>"10","sex"=>"nan"),
array("name"=>"ls","age"=>"11","sex"=>"nan"),
array("name"=>"ww","age"=>"12","sex"=>"nv"),
array("name"=>"ls","age"=>"11","sex"=>"nan"),
array("name"=>"ww","age"=>"12","sex"=>"nv"),
array("name"=>"ls","age"=>"11","sex"=>"nan"),
array("name"=>"ww","age"=>"12","sex"=>"nv")
);

echo '<table border="1" width="800" align>';
echo '<caption><h1>数组转化为表格</h1><caption>';

foreach( $group as $row ){
echo '<tr>';
foreach( $row as $col ){
echo "<td>{$col}</td>";
}
echo '</tr>';
}
echo '</table>';

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2