Oi :) Nepamanīju niansi par vienādu vietu un vietas izlaišanu, ja vienādi punkti.
Kaut kas šāds (plain & stupid) risinās problēmu PHP pusē:
<?php
$array = [
[
'Name' => 'Bob Johnson',
'Points' => 75,
'Points2' => 68,
'TotalPoints' => 143,
],
[
'Name' => 'John Doe',
'Points' => 80,
'Points2' => 72,
'TotalPoints' => 152,
],
[
'Name' => 'Emily Davis',
'Points' => 85,
'Points2' => 67,
'TotalPoints' => 152,
],
[
'Name' => 'Jane Smith',
'Points' => 90,
'Points2' => 82,
'TotalPoints' => 172,
],
];
$place = 1;
$previousTotalPoints = null;
$increment = 1;
foreach ($array as $row) {
$totalPoints = $row['TotalPoints'];
if ($previousTotalPoints) {
if ($totalPoints == $previousTotalPoints) {
$increment++; // only increment - place is the same as before
} else {
$place += $increment; // place equals previous place + the increment (how many had the same points)
$increment = 1; // reset the increment (normally each next place is +1)
}
}
echo sprintf(
'Place: %d - Name: %s - Points: %d - Points2: %d - TotalPoints: %d',
$place,
$row['Name'],
$row['Points'],
$row['Points2'],
$row['TotalPoints'],
);
echo PHP_EOL;
$previousTotalPoints = $totalPoints;
}