How can PHP be used to sort data based on multiple criteria, such as points, winnings, and stakes?

To sort data based on multiple criteria in PHP, you can use the `usort` function along with a custom comparison function. This function will compare the values of the different criteria and sort the data accordingly. You can define the criteria and their priorities within the comparison function.

// Sample data array
$data = [
    ['name' => 'Alice', 'points' => 100, 'winnings' => 500, 'stakes' => 50],
    ['name' => 'Bob', 'points' => 150, 'winnings' => 300, 'stakes' => 75],
    ['name' => 'Charlie', 'points' => 120, 'winnings' => 400, 'stakes' => 60],
];

// Custom comparison function for sorting based on multiple criteria
usort($data, function($a, $b) {
    if ($a['points'] != $b['points']) {
        return $a['points'] < $b['points'] ? 1 : -1;
    } elseif ($a['winnings'] != $b['winnings']) {
        return $a['winnings'] < $b['winnings'] ? 1 : -1;
    } else {
        return $a['stakes'] < $b['stakes'] ? 1 : -1;
    }
});

// Display sorted data
foreach ($data as $player) {
    echo $player['name'] . ' - Points: ' . $player['points'] . ', Winnings: ' . $player['winnings'] . ', Stakes: ' . $player['stakes'] . PHP_EOL;
}