How can you sort an array in PHP based on a specific key?
To sort an array in PHP based on a specific key, you can use the `array_multisort()` function. This function allows you to sort multiple arrays or a multi-dimensional array based on one or more keys. You can specify the key you want to sort by and the sorting order (ascending or descending).
// Sample array to be sorted based on a specific key
$users = array(
array('name' => 'John', 'age' => 30),
array('name' => 'Alice', 'age' => 25),
array('name' => 'Bob', 'age' => 35)
);
// Sort the array based on the 'age' key in ascending order
array_multisort(array_column($users, 'age'), SORT_ASC, $users);
// Output the sorted array
print_r($users);