Rumah > pembangunan bahagian belakang > tutorial php > 关于二维数组。解决办法

关于二维数组。解决办法

WBOY
Lepaskan: 2016-06-13 12:05:42
asal
844 orang telah melayarinya

关于二维数组。

<?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 />
Salin selepas log masuk


这样写为何不对?
------解决方案--------------------
	$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 />
Salin selepas log masuk

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan