Example 1 — Sort Numbers from High to Low
The largest number moves to the front of the array.
<?php
$scores = [3, 1, 2, 5];
rsort($scores);
echo implode(", ", $scores), PHP_EOL; How It Works
- $scores holds four numbers in no particular order.
- rsort() sorts them from largest to smallest.
- The array itself is changed, so there is no need to save a return value.
- implode() prints the sorted numbers on one line.

