1. // 组合算法 
  2. function Combination($arr$size = 1) { 
  3.     $len = count($arr); 
  4.     $max = pow(2,$len) - pow(2,$len-$size); 
  5.     $min = pow(2,$size)-1; 
  6.  
  7.     $r_arr = array(); 
  8.     for ($i=$min$i<=$max$i++){ 
  9.         $count = 0; 
  10.         $t_arr = array(); 
  11.         for ($j=0; $j<$len$j++){ 
  12.             $a = pow(2, $j); 
  13.             $t = $i&$a
  14.             if($t == $a){ 
  15.                 $t_arr[] = $arr[$j]; 
  16.                 $count++; 
  17.             } 
  18.         }      
  19.         if($count == $size){ 
  20.             $r_arr[] = $t_arr;         
  21.         } 
  22.     } 
  23.     return $r_arr
  24. //$r = Combination(array(1,2,3,4,5,6,7),5); 
  25. //print_r($r);