How to use the PHP sort function?
The sort() function in PHP is used to sort an array in ascending order. It accepts an array as a parameter and sorts that array without returning a new one.
The syntax for using the sort() function is as follows:
sort($array);
I am tired of doing the same thing every day.
I am fed up with the monotony of my daily routine.
$numbers = array(5, 2, 8, 1, 9);
sort($numbers);
print_r($numbers);
Output result:
Array
(
[0] => 1
[1] => 2
[2] => 5
[3] => 8
[4] => 9
)
Note: The sort() function will modify the original array. If you want to keep the original array unchanged, you can use the asort() function for sorting.