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
sortfunction,
which sorts in ascending order of elements -
the
ksortfunction,
which sorts in ascending order of keys -
the
krsortfunction,
which sorts in descending order of keys -
the
asortfunction,
which sorts in ascending order of elements while preserving keys -
the
arsortfunction,
which sorts in descending order of elements while preserving keys -
the
natsortfunction,
which sorts using natural order algorithm -
the
natcasesortfunction,
which sorts using natural order algorithm case-insensitively -
the
usortfunction,
which sorts using a callback function -
the
uksortfunction,
which sorts by keys using a callback function -
the
uasortfunction,
which sorts using a callback function while preserving keys -
the
array_multisortfunction,
which sorts multiple arrays