4 つの配列をシミュレートします:
$list ['a'] = array (1,2,3);
$list ['c'] =配列 (7,8,9);
では、次のような組み合わせが必要です: 14,15,16,17,18,19,24,25,26,27,28,29,34,35,36,37 ,38 ,39,47,48,49,57,58,59,67,68,69
1 つのアルゴリズムを見つける
<?php class sufa{ public function main(){ $list [‘a’] = array (1,2,3); $list [‘b’] = array (1,2); $list [‘c’] = array (1,2,3,4); // $list [‘f’] = array (1,2,3,4,5); // $list [‘d’] = array ("+","-","*","/","%"); foreach($list[‘a’] as $v){ $this->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."<br/>"; }else { $this->getsulie($list,$vv,$deep+1); } } break; } $i++; } return; } } $s = new sufa(); $s->main(); ?>
$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);
$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);
$list['a'] = array (1,2,3); $list['b'] = array (4,5,6); $list['c'] = array (7,8,9); $list['d'] = array (10,11,12);
$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);
$list['a'] = array (1,2,3); $list['b'] = array (4,5,6); $list['c'] = array (7,8,9);
コードは投稿しません。ハイライト領域で複数のバージョンを見つけることができます
アルゴリズムの観点から見ると、あなたの質問は両方とも次のようになります: 元のデータを組み合わせた結果に対してデカルト積演算を実行する( C(m,n))
コードは投稿しません。ハイライトエリアで複数のバージョンを見つけることができます