我有一个数组,里面有一个名字,然后是一个总额。然后根据他们的总排名为这个数组分配一个“总分”。每个等级积分都会减少 2,但我的问题是如何处理平局?理想情况下,我会看到有多少平局,将这些排名的总分相加,然后除以平局数,但我不知道如何真正做到这一点
这是我的数组排序:
function grossSort($gross, $compare) {
if($gross['gross'] > $compare['gross'])
return -1; // move up
else if($gross['gross'] < $compare['gross'])
return 1; // move down
else
return 0; // do nothing
}
把我的数组变成这样:
Array
(
[0] => Array
(
[instr] => lee
[gross] => 2094
)
[1] => Array
(
[instr] => steve
[gross] => 1334
)
[2] => Array
(
[instr] => nick
[gross] => 0
)
[3] => Array
(
[instr] => amber
[gross] => 0
)
[4] => Array
(
[instr] => lindsey
[gross] => 0
)
)
这就是我现在分配积分的方法:
$maxpoints = 40;
for($i = 0; $i < count($trainergross); $i++){
$trainergross[$i]['points'] += $maxpoints;
$maxpoints -=2;
}
现在我的数组看起来像这样:
Array
(
[0] => Array
(
[instr] => lee
[gross] => 2094
[points] => 40
)
[1] => Array
(
[instr] => steve
[gross] => 1334
[points] => 38
)
[2] => Array
(
[instr] => nick
[gross] => 0
[points] => 36
)
[3] => Array
(
[instr] => amber
[gross] => 0
[points] => 34
)
[4] => Array
(
[instr] => lindsey
[gross] => 0
[points] => 32
)
)
这是我的问题,有 4 人“并列”但得分越来越少,我不知道如何以我的代码设置的当前方式解决这个问题。有人有什么指导吗?