时间:2021-07-01 10:21:17 帮助过:5人阅读
$arr = array(
array( "A", "B", "C"),
array("1", "2", "3", "4"),
array("X", "Y", "Z"),
);
function foo($d) {
$r = array_pop($d);
while($d) {
$t = array();
foreach(array_pop($d) as $k1=>$x) {
foreach($r as $k2=>$y) $t[] = "$x $y";
}
$r = $t;
}
return $r;
}
print_r(foo($arr));
Array
(
[0] => A 1 X
[1] => A 1 Y
[2] => A 1 Z
[3] => A 2 X
[4] => A 2 Y
[5] => A 2 Z
[6] => A 3 X
[7] => A 3 Y
[8] => A 3 Z
[9] => A 4 X
[10] => A 4 Y
[11] => A 4 Z
[12] => B 1 X
[13] => B 1 Y
[14] => B 1 Z
[15] => B 2 X
[16] => B 2 Y
[17] => B 2 Z
[18] => B 3 X
[19] => B 3 Y
[20] => B 3 Z
[21] => B 4 X
[22] => B 4 Y
[23] => B 4 Z
[24] => C 1 X
[25] => C 1 Y
[26] => C 1 Z
[27] => C 2 X
[28] => C 2 Y
[29] => C 2 Z
[30] => C 3 X
[31] => C 3 Y
[32] => C 3 Z
[33] => C 4 X