How can arrays be sorted alphabetically based on a specific key in PHP?

To sort an array alphabetically based on a specific key in PHP, you can use the `array_multisort()` function along with a custom sorting function. This function will allow you to specify the key by which to sort the array.

// Sample array to be sorted
$students = array(
    array('name' => 'Alice', 'age' => 20),
    array('name' => 'Bob', 'age' => 22),
    array('name' => 'Charlie', 'age' => 21)
);

// Custom sorting function
function customSort($a, $b) {
    return strcmp($a['name'], $b['name']);
}

// Sort the array based on the 'name' key
usort($students, 'customSort');

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