How can the array_multisort function be used effectively in PHP to sort multiple arrays?

To sort multiple arrays simultaneously in PHP, you can use the array_multisort function. This function can be used to sort multiple arrays based on the values of one of the arrays. By passing the arrays as arguments to the function along with the sorting order, you can effectively sort all arrays in sync.

// Sample arrays to be sorted
$names = ['John', 'Alice', 'Bob'];
$ages = [25, 30, 22];

// Sort the names array and maintain the correlation with the ages array
array_multisort($names, $ages);

// Display the sorted arrays
print_r($names);
print_r($ages);