請考慮我擁有以下總分數組,其中每個值都是錦標賽中玩家的分數。PHP - 從數組中創建錦標賽結果訂單
$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名。 – Max