日期:2014-05-17 浏览次数:20505 次
<?php $color = array("红", "黄", "蓝"); $size = array("大", "小"); $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); print_r($ret); ?>