PHP自动分组程序,可设置轮空组,可用于自动分组功能,如足球比赛等
public function demo2() { $total = 32; //总数 $bye = 2; //指定轮空的队伍,可为空 if($bye!=''){ $res[] = '轮空组:'.$bye; $arr_count = $total-1; for($i = 1; $i<=$arr_count+1; $i++){ if($i!=$bye){ $arr[] = $i; } } }else{ $arr_count = $total; for($i = 1; $i<=$arr_count+1; $i++){ $arr[] = $i; } } $fornumber = floor($arr_count/2); for($j=1; $j<=$fornumber; $j++){ for($k=1; $k<=2; $k++){ $rand = rand(0,$arr_count-1); $res[$j][] = $arr[$rand]; unset($arr[$rand]); $arr = array_values($arr); $arr_count = $arr_count - 1; } } if(!empty($arr)){ $res[] = $arr; } var_dump($res); exit; }
版权声明:本站所提供的文章、图片等内容均为用户发布或互联网整理而来,仅供学习参考,如有侵犯您的版权,请联系我们客服人员删除。