How can a multidimensional array in PHP be sorted based on a specific key within the inner arrays?
To sort a multidimensional array in PHP based on a specific key within the inner arrays, you can use the `array_multisort()` function. This function allows you to sort multiple arrays or multidimensional arrays based on one or more key values. By specifying the key you want to sort by, you can reorder the inner arrays accordingly.
<?php
// Sample multidimensional array
$multiArray = array(
array('name' => 'John', 'age' => 25),
array('name' => 'Alice', 'age' => 30),
array('name' => 'Bob', 'age' => 20)
);
// Sort the multidimensional array based on the 'age' key
array_multisort(array_column($multiArray, 'age'), SORT_ASC, $multiArray);
// Output the sorted array
print_r($multiArray);
?>