function getCombinAryByNum( $a, $n,$t=array()) { if ($n == 0) { return array($t); } $r = array(); for ($i=0,$l=count($a); $i <= $l-$n; $i++) { $tmp = getCombinAryByNum( array_slice($a, $i+1, $l, false), $n-1,array_merge($t, array($a[$i]))); $r = array_merge($r, $tmp); } return $r; } $ss = getCombinAryByNum(array(1,2,3,4,5,6,7,8),2); print_r($ss);