【发布时间】:2016-07-29 11:00:36
【问题描述】:
假设我有以下总分数组,每个值都是锦标赛中玩家的分数。
$total_scores = array(350,200,150,150,75,75,75,0);
我需要创建一个表格,列出位置正确的球员,如果他们得分相同,列表应该反映这一点,即:
1. Player 1 350
2. Player 2 200
3.-4. Player 3 150
3.-4. Player 4 150
5.-7. Player 5 75
5.-7. Player 6 75
5.-7. Player 7 75
8. Player 8 0
我试图做一些事情
foreach ($total_scores as $total_score) {
$no_of_occurrences = array_count_values($total_scores)[$total_score];
}
但无法弄清楚如何建立正确的位置编号。
【问题讨论】:
-
3.-4.等等是什么意思?有必要吗? -
是他们在排名中的位置范围。玩家 3 和玩家 4 各有 150 分,因此并列排名第 3 和第 4 位。