gpt4 book ai didi

php - 如何用php给分数打分

转载 作者:行者123 更新时间:2023-11-29 15:21:40 25 4
gpt4 key购买 nike

我正在尝试根据获得的最高平均值对一些分数进行评分。这是我的脚本

$scores_AND_ID = 'M2377O=100,M2727B=100,M5821K=100,M7492F=97.75,M7973O=96,M3487I=94,M7969O=93.13,M1452V=92.5,M4653O=92.38,M4158J=92.25,M2881A=89.38,M6112S=28.63,';
$out_score = chop($scores_AND_ID, ',');
$rr2 = explode(",", $out_score);


$array_un = array_unique($rr2);
foreach ($array_un as $key => $value) {
if ($value == "") {
continue;
}


$postion = positionNumbers($key);//1st,2nd,3rd function
$sec = explode("=", $value);
rsort($sec);
$stdntID = $sec[0]; //Student number
$stdntAV = $sec[1]; //Student Average

mysql_query("UPDATE score_table SET grade='$postion' WHERE avg='$stdntAV' ");

}

我正在使用 foreach 键来分配成绩位置,但无法正常工作。 这是我的结果 Current rsult

这就是我需要实现的目标。

    1. 100---1st
2. 100---1st
3. 100---1st
4. 98---4th
5. 89.5--5th
6. 89---6th
7. 89---6th
8. 80---8th

谢谢大家

最佳答案

我认为你想要的代码是这样的:

<?php

$scores_AND_ID = 'M7492F=97.75,M7973O=96,M3487I=94,M2377O=100,M2727B=100,M5821K=100,M7969O=93.13,M1452V=92.5,M4653O=92.38,M4158J=92.25,M2881A=89.38,M6112S=28.63,';

// Gets all of the entries from the source string
$scores_array = array_unique(array_filter(explode(',', $scores_AND_ID)));

// Sets up an associative array of values (student id => score)
$score_map = [];
foreach ($scores_array as $record) {
[ $student_id, $score ] = explode('=', $record);

$score_map[$student_id] = $score;
}

// Ensure values are sorted numerically descending
uasort($score_map, function ($a, $b) {
if ($a > $b) {
return -1;
}
if ($a == $b) {
return 0;
}

return 1;
});

// Gets the maximum value from the scores
$previous_score = max(array_values($score_map));

$rank = 1;
$incrementer = 0;
foreach ($score_map as $student => $score) {
// If the score hasn't changed from it's previous value
// we increment a counter instead of the rank
if ($score == $previous_score) {
$incrementer++;
// Once it's changed, we update the rank based on the incrementer
// and then reset the incrementer
} else {
$rank += $incrementer;
$incrementer = 1;
}

$previous_score = $score;

// Updating database is left as an exercise to the reader
}

关于php - 如何用php给分数打分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59345859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com