What are some common sorting functions in PHP for arrays with multiple dimensions?
When working with arrays containing multiple dimensions in PHP, sorting them can be a bit more complex compared to sorting one-dimensional arrays. To sort multidimensional arrays, we can use functions like `array_multisort()` or `usort()` along with custom comparison functions. These functions allow us to sort the arrays based on specific keys or values within the subarrays.
// Example of sorting a multidimensional array by a specific key using array_multisort()
$students = [
['name' => 'Alice', 'age' => 20],
['name' => 'Bob', 'age' => 22],
['name' => 'Charlie', 'age' => 21]
];
// Sort the array by 'age' key in ascending order
array_multisort(array_column($students, 'age'), SORT_ASC, $students);
print_r($students);