从1-100中挑选出10个不同的数字,把可能的所有组合都打印出来
$data1=range(0, 9); foreach($data1 as $k1=>$v1) { $data2=getUnsetArray($k1,$data1); foreach($data2 as $k2=>$v2) { $data3=getUnsetArray($k2,$data2); foreach($data3 as $k3=>$v3) { $count++; echo "$k1 $k2 $k3","<br/>"; } } }
function getUnsetArray($key,$array) { if(isset($array)) { unset($array[$key]); } return $array; }
方法2: $count=0; for($i=0;$i<=9;$i++) { for($j=0;$j<=9;$j++) { if($j==$i) continue; for($k=0;$k<=9;$k++) { if($k==$i || $k==$j) continue; $count++; echo "$i $j $k","<br/>"; } } }