Sort the elements in the array $cars alphabetically in descending order:
<?php$cars=array("Volvo","BMW","Toyota");rsort($cars);?>The rsort() function sorts a numeric array in descending order.
Tip: Use the sort() function to sort a numeric array in ascending order.
rsort( array,sortingtype );
parameter | describe |
---|---|
array | Required. Specifies the array to be sorted. |
sortingtype | Optional. Specifies how the elements/items of an array are arranged. Possible values: 0 = SORT_REGULAR - Default. Put each item in regular order (Standard ASCII, don't change the type). 1 = SORT_NUMERIC - treat each item as a number. 2 = SORT_STRING - Treat each item as a string. 3 = SORT_LOCALE_STRING - Treat each item as a string, based on the current locale (can be changed with setlocale()). 4 = SORT_NATURAL - Treat each item as a string, using natural sorting like natsort(). 5 = SORT_FLAG_CASE - Strings can be sorted in combination (bitwise OR) with SORT_STRING or SORT_NATURAL, case-insensitively. |
Return value: | Returns TRUE if successful and FALSE if failed. |
---|---|
PHP version: | 4+ |
Sort the elements in the array $numbers in descending numerical order:
<?php$numbers=array(4,6,2,22,11);rsort($numbers);?>Treat each item as a number and sort the elements in the $cars array in descending order:
<?php$cars=array("Volvo","BMW","Toyota");rsort($cars,SORT_NUMERIC);?>