php8.5
Home/ Manual/ array / functions/ rsort

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

array

The input array.

Return Values

Always

Changelog

VersionDescription

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 = apple

The fruits have been sorted in reverse alphabetical order.

See Also

Source: reference/array/functions/rsort.xml · from the official PHP manual (php/doc-en)