How can the usort function be effectively utilized to sort a multidimensional array in PHP based on specific values within the subarrays?

To sort a multidimensional array in PHP based on specific values within the subarrays, the usort function can be utilized. This function allows for custom sorting logic to be applied to the array elements. By defining a custom comparison function that specifies the sorting criteria based on the specific values within the subarrays, the multidimensional array can be sorted accordingly.

// Sample multidimensional array
$multiArray = [
    ['name' => 'John', 'age' => 30],
    ['name' => 'Alice', 'age' => 25],
    ['name' => 'Bob', 'age' => 35]
];

// Custom comparison function to sort based on 'age' value in subarrays
usort($multiArray, function($a, $b) {
    return $a['age'] <=> $b['age'];
});

// Output the sorted multidimensional array
print_r($multiArray);