How can you sort a multidimensional array in PHP based on a specific subarray value?
To sort a multidimensional array in PHP based on a specific subarray value, you can use the `array_multisort()` function along with a custom sorting function. This function allows you to specify the subarray key that you want to sort by. By using this approach, you can easily reorganize the multidimensional array based on the values of a specific subarray.
// Sample multidimensional array
$students = array(
array('name' => 'Alice', 'age' => 20),
array('name' => 'Bob', 'age' => 22),
array('name' => 'Charlie', 'age' => 18)
);
// Sort the multidimensional array based on the 'age' subarray value
array_multisort(array_column($students, 'age'), SORT_ASC, $students);
// Print the sorted array
print_r($students);