rsort()
function sorts the numeric array in descending order.
Tip: Please use the sort() function to sort the numeric array in ascending order.
Sort elements in array $cars in descending order:
<?php $cars = array ( "Volvo" , "BMW" , "Toyota" ) ; rsort ( $cars ) ; ?>
Try it yourself
Sort elements in array $numbers in descending order by number:
<?php $numbers = array ( 4 , 6 , 2 , 22 , 11 ) ; rsort ( $numbers ) ; ?>
Try it yourself
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 ) ; ?>
Try it yourself
rsort ( array , sortingtype ) ;
parameter | describe |
---|---|
array | Required. Specifies the array to be sorted. |
sortingtype |
Optional. Specifies how to compare elements/items of an array. Possible values:
|
The rsort()
function reverses the elements of the array by key values. The function is basically the same as arsort()
.
Note: This function assigns a new key name to the cells in the array . This will remove the original key name instead of reordering.
Return TRUE if successful, otherwise return FALSE.
The optional second parameter contains additional sorting flags.