The sort() function is used to sort array elements. Elements will be arranged from lowest to highest when this function has completed.
Tip: Use the rsort() function to sort an indexed array in descending order.
TRUE on success. FALSE on failure
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
sortingtype | Optional. Specifies how to compare the array elements/items. Possible values: |
Syntax
sort(array,sortingtype);
Example
$numbers=array(4,6,2,22,11);
sort($numbers);
print_r($numbers);
Output
Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 11 [4] => 22 )