What are the best practices for handling tie-breakers in ranking algorithms when multiple participants achieve the same score in a competition?

When multiple participants achieve the same score in a competition, tie-breakers are necessary to determine their final ranking. One common approach is to use secondary criteria, such as the time taken to achieve the score or the number of correct answers in a quiz, to break the tie. Another option is to assign equal rankings to the tied participants and adjust the subsequent rankings accordingly.

// Sample code to handle tie-breakers in ranking algorithm

// Assuming $participants is an array of participants with their scores
// Sort the participants by score in descending order
usort($participants, function($a, $b) {
    return $b['score'] - $a['score'];
});

// Assign initial ranks based on score
$rank = 1;
foreach ($participants as $key => $participant) {
    $participant['rank'] = $rank;
    // Check for tie with next participant
    if (isset($participants[$key + 1]) && $participant['score'] == $participants[$key + 1]['score']) {
        // Handle tie-breaker here (e.g. time taken, correct answers)
        // Adjust rank accordingly
    } else {
        $rank++;
    }
}