How can you sort an array based on a specific key in a subarray in PHP?

To sort an array based on a specific key in a subarray in PHP, you can use the `array_multisort()` function. This function allows you to specify the key you want to sort by in the subarray. You can use a loop to iterate through the subarray and extract the key values you want to sort by, then use `array_multisort()` to sort the main array based on those values.

// Sample array with subarrays
$data = [
    ['name' => 'John', 'age' => 30],
    ['name' => 'Jane', 'age' => 25],
    ['name' => 'Alice', 'age' => 35]
];

// Extract the 'age' values from the subarrays
$ages = array_column($data, 'age');

// Sort the main array based on the 'age' values
array_multisort($ages, SORT_ASC, $data);

// Output the sorted array
print_r($data);