首頁 > 後端開發 > php教程 > 关于二维数组。解决办法

关于二维数组。解决办法

WBOY
發布: 2016-06-13 12:05:42
原創
842 人瀏覽過

关于二维数组。

<?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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板