アルゴリズムについてです。助けてください
$arr = array(
array( "A", "B", "C"),
array("1", "2", "3 " 、"4")、
array("X"、"Y"、"Z")、
..... .....
);
そのような数値を次のように表示する方法 (配列のサイズは可変です)
A 1 X
A 1 Y
A 1 Z
A 2 X
A 2 Y
A 2 Z
A 3 X
A 3 Y
A 3 Z
A 4 X
B 2 Y
B 2 Z
B 3 X
B 3 Y
B 3 Z
B 4 X
B 4 Y
B 4 Z
C 1 X
C 1 Y
C 1 Z
C 2 X
C 2 Y
C 2 Z
C 3 X
C 3 Y
C 3 Z
C 4 >
これは出力要件を満たします
配列
(
[0] => A 1 X
[1] => A 1 Y
[2] => A 1 Z
[4] => A 2 Y
[5] =>
[6] = > A 3 A 4 Y [11] => A 4 Z [13] =>
[14] => B 1 Z
$arr = array(<br /> array( "A", "B", "C"),<br /> array("1", "2", "3", "4"),<br /> array("X", "Y", "Z"),<br />);<br /> <br />function foo($d) {<br /> $r = array_pop($d);<br /> while($d) {<br /> $t = array();<br /> foreach(array_pop($d) as $k1=>$x) {<br /> foreach($r as $k2=>$y) $t[] = "$x $y";<br /> }<br /> $r = $t;<br /> }<br /> return $r;<br />}<br />print_r(foo($arr));<br />[15] => B 2 🎜> [20] => B 3 Z
21] => B 4 X<br> [22] => B 4 Z<br> [25] =>C1Y<br> [26] => C 1 Z<br> [27] => C 2 X<br> [28] => C 2 Y<br> [29] => C 2 Z<br> [30] => C 3 X<br> [31] => C 3 Y<br> [32] => C 3 Z<br> [33] => C 4 X<div class="clear"></div>