How do I get this combination? Get the result of permutations and combinations
Properties: Color red, yellow, blue ....
Big size, small ....
Capacity 1g,2g,3g,5g ...
。。。。。。。。。
All combinations of property values are required:
such as red big, red small, red big 1G, red small 1G, red small 2G ... Big Blue,. Blue 1G ....
------Solution--------------------
PHP code
!--? Php$color = Array ("Red", "yellow", "blue"); $size = Array ("Large", "small"), $cap = Array ("1G", "2G", "3G", "5G"), $foo = Array ($color, $size, $cap); function Get_all ($e) { $elem _total = count ($e); $max = 1; for ($i =0; $i $elem _total; $i + +) {$len = count ($e [$i]) +1; $elem _size[] = $len; $max *= $len; } for ($i =1; $i $max; $i + +) {$m = $i; $item = ""; $ct = 0; for ($j =0; $j $elem _total; $j + +) {$n = $m% $elem _size[$j]; $item. = $n-->0? $e [$j] [$n-1]: ""; $ct + = $n >0?1:0; $m = (int) ($m/$elem _size[$j]); if ($ct >=2) $all [] = $item; } return $all;} $ret = Get_all ($foo);p rint_r ($ret);?