PHP rsort() function
Example
Sort the elements of the array $cars in alphabetical order in descending order:
<?php $cars=array("Volvo","BMW","Toyota"); rsort($cars); ?>
Definition and Usage
The rsort() function sorts a numerical array in descending order.
Tip:Please use sort() The function sorts a numerical array in ascending order.
Syntax
rsort(array,sortingtype);
Parameter | Description |
---|---|
array | Required. Specify the array to be sorted. |
sortingtype |
Optional. Specify how to compare the elements/items of an array. Possible values:
|
Description
The rsort() function sorts the elements of an array in reverse order by key value. It is similar in function to arsort().
Note:This function is for array Assigns new key names to the units. This will delete the original key names rather than just reordering.
Returns TRUE if successful, otherwise FALSE.
The optional second parameter includes additional sorting flags.
Technical Details
Return Value: | TRUE on success. FALSE on failure |
PHP Version: | 4+ |
More Examples
Example 1
Sort the elements in the array $numbers in descending order by number:
<?php $numbers=array(4,6,2,22,11); rsort($numbers); ?>
Example 2
Compare items as numbers and sort the elements in the array $cars in descending order:
<?php $cars=array("Volvo","BMW","Toyota"); rsort($cars,SORT_NUMERIC); ?>