php 系统评分 已知评分总人数,最终评分 粗略规划各等级评分人数
public function score() { $rateTotal = 25;//总评分人数 $rateScore = 7.5;//最终评分 10分制 $totalScore = intval($rateTotal * $rateScore / 2); //总评分 转化为5分制 $percent = $rateScore / 10; $grade = [5, 4, 3, 2, 1]; $data = []; foreach ($grade as $item) { if ($item == 1) { $num = intval($totalScore); } else { $num = intval($totalScore * $percent / $item);//向下取整,就不用考虑数据超出的问题 } $totalScore = $totalScore - $num * $item; $data[$item] = $num; } var_dump($data); }