首页 > 后端开发 > php教程 > 关于二维数组。解决办法

关于二维数组。解决办法

WBOY
发布: 2016-06-13 12:05:42
原创
844 人浏览过

关于二维数组。

<?php<br />	$group1 = array(<br />            ("name"=>"zs","age"=>"10","sex"=>"nan"),<br />            ("name"=>"zs","age"=>"10","sex"=>"nan"),<br />            ("name"=>"zs","age"=>"10","sex"=>"nan"),<br />            ("name"=>"ls","age"=>"11","sex"=>"nan"),<br />            ("name"=>"ww","age"=>"12","sex"=>"nv"),<br />            ("name"=>"ls","age"=>"11","sex"=>"nan"),<br />            ("name"=>"ww","age"=>"12","sex"=>"nv"),<br />            ("name"=>"ls","age"=>"11","sex"=>"nan"),<br />            ("name"=>"ww","age"=>"12","sex"=>"nv")<br />	);<br /><br />	echo '<table border="1" width="800" align>';<br />	echo '<caption><h1>数组转化为表格</h1><caption>';<br /><br />	foreach( $group as $row ){<br />		echo '<tr>';<br />		foreach( $row as $col ){<br />			echo '<td>{$col}</td>';<br />		}<br />		echo '</tr>';<br />	}<br />	echo '</table>';<br />?><br />
登录后复制


这样写为何不对?
------解决方案--------------------
	$group = array(<br />            array("name"=>"zs","age"=>"10","sex"=>"nan"),<br />            array("name"=>"zs","age"=>"10","sex"=>"nan"),<br />            array("name"=>"zs","age"=>"10","sex"=>"nan"),<br />            array("name"=>"ls","age"=>"11","sex"=>"nan"),<br />            array("name"=>"ww","age"=>"12","sex"=>"nv"),<br />            array("name"=>"ls","age"=>"11","sex"=>"nan"),<br />            array("name"=>"ww","age"=>"12","sex"=>"nv"),<br />            array("name"=>"ls","age"=>"11","sex"=>"nan"),<br />            array("name"=>"ww","age"=>"12","sex"=>"nv")<br />	);<br /><br />	echo '<table border="1" width="800" align>';<br />	echo '<caption><h1>数组转化为表格</h1><caption>';<br /><br />	foreach( $group as $row ){<br />		echo '<tr>';<br />		foreach( $row as $col ){<br />			echo "<td>{$col}</td>";<br />		}<br />		echo '</tr>';<br />	}<br />	echo '</table>';<br />
登录后复制

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板