Algorithm for array combination
PHP Code
Array (2) { [8] = = Array (2) { [0] = = string (2) "" [1] = = string (2) "" } [9] = = Array (2) { [0] = = string (2) "" " [1] = = string (2)" "} }
A combination of 2 arrays with multiple arrays? Master, please.
------Solution--------------------
Phpnewnew Moderator discussed this, portal
Http://topic.csdn.net/u/20120325/11/cb8beb24-845c-4d16-be52-92f74b21a30c.html
------Solution--------------------
It's a question of Cartesian product.
PHP code
$ar = Array (8 + = Array (' 9 ', ' + '), + = = Array ( ' + '),;p Rint_r (Descartes ($ar)), function Descartes () {$t = Func_get_args (); if (Func_num_args () = = 1) return Call_user_func_array (__function__, $t [0]); $a = Array_shift ($t); if (! Is_array ($a)) $a = array ($a); $a = Array_chunk ($a, 1); do {$r = array (); $b = Array_shift ($t); if (! Is_array ($b)) $b = Array ($b); foreach ($a as $p) foreach (Array_chunk ($b, 1) as $q) $r [] = Array_merge ($p, $q); $a = $r; }while ($t); return $r;}