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

To sort PHP arrays based on a specific key value, you can use the `array_multisort()` function along with a custom sorting function. This function allows you to specify which key to sort the array by. First, extract the values of the key you want to sort by into a separate array, then use `array_multisort()` to sort both the original array and the extracted values array based on the key values.

// Sample array to be sorted based on 'name' key
$users = [
    ['name' => 'John', 'age' => 30],
    ['name' => 'Alice', 'age' => 25],
    ['name' => 'Bob', 'age' => 35]
];

// Extract 'name' values into a separate array for sorting
foreach ($users as $key => $row) {
    $names[$key] = $row['name'];
}

// Sort both arrays based on 'name' values
array_multisort($names, SORT_ASC, $users);

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