Please help me. how can I deal with this change? php array combination. for example, I have two arrays.
Group A: 10, 11, 12, 13
Group B: 14,15
To be combined into 10 | 15
Thanks. three or four groups may occur, for example, Group A, Group B, Group C, and Group D.
Reply to discussion (solution)
You are seeking Cartesian product. There are several discussions in the essence area.
Here we will give another version.
$a = array(10,11,12,13);$b = array(14,15);foreach(Descartes($a, $b) as $v) $r[] = join(',', $v);echo join('|', $r);
|
function Descartes($d) {if(func_num_args() > 1) $d = func_get_args();$r = array_pop($d);while($d) {$t = array();$s = array_pop($d);if(! is_array($s)) $s = array($s);foreach($s as $x) {foreach($r as $y) $t[] = array_merge(array($x), is_array($y) ? $y : array($y));}$r = $t;}return $r; }
You are seeking Cartesian product. There are several discussions in the essence area.
Here we will give another version.
$a = array(10,11,12,13);$b = array(14,15);foreach(Descartes($a, $b) as $v) $r[] = join(',', $v);echo join('|', $r);
|
function Descartes($d) {if(func_num_args() > 1) $d = func_get_args();$r = array_pop($d);while($d) {$t = array();$s = array_pop($d);if(! is_array($s)) $s = array($s);foreach($s as $x) {foreach($r as $y) $t[] = array_merge(array($x), is_array($y) ? $y : array($y));}$r = $t;}return $r; }
Thank you, moderator. I will test it later. I will release another requirement later. I will help you later.
Http://bbs.csdn.net/topics/391860657 God help me look at this