rsort
PHP function
Edit on GitHub ✎
(PHP 4, PHP 5, PHP 7, PHP 8)
Sort an array in descending order
Description
rsort(array $array, int $flags = SORT_REGULAR): true
Sorts array in place by values in descending order.
Sort-unstable No-key-association Reset-index
Parameters
arrayThe input array.
Return Values
Always
Changelog
| Version | Description |
|---|
Examples
rsort() example
php
<?php
$fruits = array("lemon", "orange", "banana", "apple");
rsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>The above example will output:
output
0 = orange
1 = lemon
2 = banana
3 = appleThe fruits have been sorted in reverse alphabetical order.