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; } $arr = [ ['3101','3102','3103'], ['3201','3202'], ]; $tmp = Descartes($arr); print_r($tmp);