How to Sort Numbers of an Array in Descending Order in PHP

PHP


In this article, we show how to sort numbers of an array in descending order in PHP.

To sort an array of numbers in descending order in PHP, we use the rsort() function.

Let's say we have the array of numbers below:

$numbers= array(48, 93, 4, 6, 21, 11, 32, 17);

And now we want this array to be shown and ordered in descending order numerically.

We use the sort() function to put it in descending order.

The general form to put an array of numbers in descending order:

rsort($array_name);

where $array_name is the name of the array we want to sort in descending order numerically.

For the above array we created, the code to put it in descending order is:

rsort($numbers);

PHP Output

93 48 32 21 17 11 6 4

HTML Comment Box is loading comments...