Home > Backend Development > PHP Tutorial > 关于二维数组。解决办法

关于二维数组。解决办法

WBOY
Release: 2016-06-13 12:05:42
Original
843 people have browsed it

关于二维数组。

<?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 />
Copy after login


这样写为何不对?
------解决方案--------------------
	$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 />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template