The rsort Function
The rsort
function sorts an array
in descending order.
The function modifies the array itself.
Syntax
rsort(array &$array, int $flags = SORT_REGULAR): bool
Example
Let's sort an array in descending order:
<?php
$arr = [1, 3, 2, 5, 4];
rsort($arr);
var_dump($arr);
?>
Code execution result:
[5, 4, 3, 2, 1]
See Also
-
the
sort
function,
which sorts in ascending order of elements -
the
ksort
function,
which sorts in ascending order of keys -
the
krsort
function,
which sorts in descending order of keys -
the
asort
function,
which sorts in ascending order of elements while preserving keys -
the
arsort
function,
which sorts in descending order of elements while preserving keys -
the
natsort
function,
which sorts using natural order algorithm -
the
natcasesort
function,
which sorts using natural order algorithm case-insensitively -
the
usort
function,
which sorts using a callback function -
the
uksort
function,
which sorts by keys using a callback function -
the
uasort
function,
which sorts using a callback function while preserving keys -
the
array_multisort
function,
which sorts multiple arrays