Heim  >  Artikel  >  Backend-Entwicklung  >  请问二维数组矩阵算法

请问二维数组矩阵算法

WBOY
WBOYOriginal
2016-06-13 12:01:50956Durchsuche

请教二维数组矩阵算法

<br />$ary = array(<br />	'a'=>array('a1','a2'),<br />	'b'=>array('b1','b2'),<br />	'c'=>array('c1','c2'),<br />);<br />

如何把上面的数组,输出到页面成这样啊

------解决方案--------------------
<br /><br />echo '<table width="150px" border="1">';<br />foreach($ary['a'] as $aV){<br />	foreach($ary['b'] as $bV){<br />		foreach($ary['c'] as $cV){<br />			echo "<tr><td>$aV</td><td>$bV</td><td>$cV</td></tr>";<br />		}<br />	}<br />}<br />echo '</table>';<br /><br />

------解决方案--------------------

本帖最后由 xuzuning 于 2014-07-10 18:39:24 编辑
$ary = array(<br />    'a'=>array('a1','a2'),<br />    'b'=>array('b1','b2'),<br />    'c'=>array('c1','c2'),<br />);<br /><br />echo "<table>\n";<br />echo "<tr><td>a</td><td>b</td><td>c</td></tr>\n";<br />foreach($ary['a'] as $m) {<br />  foreach($ary['b'] as $n) {<br />    foreach($ary['c'] as $v) {<br />      echo "<tr><td>$m</td><td>$n</td><td>$v</td></tr>\n";<br />    }<br />  }<br />}<br />echo "</table>";
[code=html]









a b c
a1 b1 c1
a1 b1 c2
a1 b2 c1
a1 b2 c2
a2 b1 c1
a2 b1 c2
a2 b2 c1
a2 b2 c2

/code]
------解决方案--------------------
精华区 迪尔卡积  我问的问题....前后几篇 很完整了
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn