Evaluate the php multi-array combination arrangement algorithm to simulate four arrays:
$ List ['A'] = array (1, 2, 3 );
$ List ['B'] = array (4, 5, 6 );
$ List ['c'] = array (7, 8, 9 );
Combination of requirements:, 68, 69
Algorithm
Reply to discussion (solution)
A piece of code is displayed on the Internet:
getsulie($list,$v,1); } } function getsulie($list,$content,$deep){ $i=0; if($deep>count($list)){ return; } foreach($list as $k=>$v){ if($i==$deep){ foreach($list[$k] as $vv){ $vv = $content.$vv; if($deep==count($list)-1){ echo $vv."
"; }else { $this->getsulie($list,$vv,$deep+1); } } break; } $i++; } return; } } $s = new sufa(); $s->main(); ?>
But this is not the same.
Recursion is not easy to use. please kindly advise
$list['a'] = array (1,2,3);$list['b'] = array (4,5,6);$list['c'] = array (7,8,9);foreach($list as $key=>$row) { unset($list[$key]); foreach($row as $col) { foreach($list as $r) foreach($r as $v) $res[] = $col . $v; }}echo join(',', $res);
, 69
$list['a'] = array (1,2,3);$list['b'] = array (4,5,6);$list['c'] = array (7,8,9);foreach($list as $key=>$row) { unset($list[$key]); foreach($row as $col) { foreach($list as $r) foreach($r as $v) $res[] = $col . $v; }}echo join(',', $res);
, 69
A positive solution, how can we implement a combination of three numbers, such
$list['a'] = array (1,2,3);$list['b'] = array (4,5,6);$list['c'] = array (7,8,9);$list['d'] = array (10,11,12);
Finally, you need to get:
147,148,149,157,158,159,167,168,169,247,248,249,257,258,259,267,268,269,347,348,349,357,358,359,367,368,369
$list['a'] = array (1,2,3);$list['b'] = array (4,5,6);$list['c'] = array (7,8,9);foreach($list as $key=>$row) { unset($list[$key]); foreach($row as $col) { foreach($list as $r) foreach($r as $v) $res[] = $col . $v; }}echo join(',', $res);
, 69
I wrote an error and wrote an array,
$list['a'] = array (1,2,3);$list['b'] = array (4,5,6);$list['c'] = array (7,8,9);
Finally, you need to get:
147,148,149,157,158,159,167,168,169,247,248,249,257,258,259,267,268,269,347,348,349,357,358,359,367,368,369
I thought you were in urgent need of solving problems at work. I didn't think you were studying algorithms.
From an algorithm perspective, your two questions should be: perform Cartesian product operations on the result of the combination of the original data (C (m, n ).
The code will not be pasted. you can find multiple versions in the essence area.
I thought you were in urgent need of solving problems at work. I didn't think you were studying algorithms.
From an algorithm perspective, your two questions should be: perform Cartesian product operations on the result of the combination of the original data (C (m, n ).
The code will not be pasted. you can find multiple versions in the essence area.
Thank you.