How can PHP's sort() and rsort() functions be used effectively to sort arrays with multiple values in PHP?
When sorting arrays with multiple values in PHP, you can use the sort() and rsort() functions along with array_multisort() to effectively sort the arrays based on different values within the array. By specifying the key or index to sort the array on, you can achieve a customized sorting order for arrays with multiple values.
// Sample array with multiple values
$users = array(
array('name' => 'John', 'age' => 30),
array('name' => 'Alice', 'age' => 25),
array('name' => 'Bob', 'age' => 35)
);
// Sort the array based on age in ascending order
array_multisort(array_column($users, 'age'), SORT_ASC, $users);
// Print the sorted array
print_r($users);