What is the best way to sort a multidimensional array in PHP based on multiple criteria such as points and goal difference?

When sorting a multidimensional array in PHP based on multiple criteria such as points and goal difference, you can use the `usort()` function along with a custom comparison function. This function will compare the values of the two arrays based on the points first, and if they are equal, it will then compare based on goal difference.

// Sample multidimensional array
$teams = [
    ['name' => 'Team A', 'points' => 12, 'goal_difference' => 5],
    ['name' => 'Team B', 'points' => 15, 'goal_difference' => 3],
    ['name' => 'Team C', 'points' => 12, 'goal_difference' => 7],
];

// Custom comparison function
usort($teams, function($a, $b) {
    if ($a['points'] == $b['points']) {
        return $b['goal_difference'] - $a['goal_difference'];
    }
    return $b['points'] - $a['points'];
});

// Output sorted array
print_r($teams);