How can the array_multisort() function be used to sort a multidimensional array in PHP?
To sort a multidimensional array in PHP, you can use the array_multisort() function. This function allows you to sort multiple arrays or a multidimensional array based on one or more key values. You can specify the sorting order (ascending or descending) for each key. The array_multisort() function modifies the input arrays directly, so there is no need to assign the sorted array to a new variable.
// Sample multidimensional array
$multiArray = array(
array('name' => 'John', 'age' => 30),
array('name' => 'Alice', 'age' => 25),
array('name' => 'Bob', 'age' => 35)
);
// Sort the multidimensional array by 'age' in ascending order
array_multisort(array_column($multiArray, 'age'), SORT_ASC, $multiArray);
// Output the sorted array
print_r($multiArray);