What are the differences between array_multisort and usort in PHP, and when should each be used?
array_multisort is used to sort multiple arrays or a multi-dimensional array based on one or more key values, while usort is used to sort a single array using a user-defined comparison function. array_multisort is more suitable for sorting multiple arrays simultaneously, while usort is more flexible and allows for custom sorting logic. Example PHP code snippet for using array_multisort:
<?php
$names = array("John", "Alice", "Bob");
$ages = array(25, 30, 22);
array_multisort($ages, $names);
print_r($names);
print_r($ages);
?>
```
Example PHP code snippet for using usort:
```php
<?php
$numbers = array(5, 3, 8, 1, 2);
usort($numbers, function($a, $b) {
return $a - $b;
});
print_r($numbers);
?>