PHP rsort()Functions
Examples
Sort the elements in the array $cars in descending alphabetical order:
<?php
$cars=array("Volvo","BMW","Toyota");
rsort($cars);
?>
$cars=array("Volvo","BMW","Toyota");
rsort($cars);
?>
Run example »
Definition and Usage
The rsort() function sorts a numeric array in descending order.
Tip:Please usesort()function to sort a numeric array in ascending order.
Syntax
rsort(array,sortingtype);
| Parameter | Description |
|---|---|
| array | Required. Specifies the array to be sorted. |
| sortingtype | Optional. Specifies how to arrange the elements/items of the array. Possible values:
|
Technical Details
| Return Value: | Returns TRUE on success, or FALSE on failure. |
|---|---|
| PHP Version: | 4+ |
More Examples
Example 1
Sort the elements in the array $numbers in descending numeric order:
<?php
$numbers=array(4,6,2,22,11);
rsort($numbers);
?>
$numbers=array(4,6,2,22,11);
rsort($numbers);
?>
Run example »
Example 2
Treat each item as a number, and sort the elements in the array $cars in descending order:
<?php
$cars=array("Volvo","BMW","Toyota");
rsort($cars,SORT_NUMERIC);
?>
$cars=array("Volvo","BMW","Toyota");
rsort($cars,SORT_NUMERIC);
?>
Run example »
Complete PHP Array Reference Other Extensions