$avr = intval($result->markk / 11);
$numbers = array($avr);
rsort($numbers);
$arr = $arr1 = array();
$i = $rank = 1;
foreach ($numbers as $key => $value) {
$arr[$value][] = $value;
}
foreach ($arr as $key => $value) {
foreach ($value as $key1 => $value1) {
echo $value1 . "- rank " . $rank . "<br>";
$rank++; // Increment the rank
}
$i++;
}
上面的代码只显示了一个等级,我如何解决这个问题
rank 1
rank 2
rank 2
rank 4
您需要将所有学生的平均分放入
$numbers
,而不仅仅是一个平均分。
$numbers = [];
foreach ($results as $result) {
$numbers[] = round($result->markk / 11);
}