洗牌算法
<?php $card_num = 54;//牌数 function wash_card($card_num){ $cards = $tmp = array(); for($i = 0;$i < $card_num;$i++){ $tmp[$i] = $i; } for($i = 0;$i < $card_num;$i++){ $index = rand(0,$card_num-$i-1); $cards[$i] = $tmp[$index]; unset($tmp[$index]); //删掉临时的 $tmp = array_values($tmp);//重新排序 } return $cards; } var_dump(wash_card($card_num));