How to Sort Strings of an Array in Descending Order in PHP
In this article, we show how to sort strings of an array in descending order in PHP.
To sort an array of strings in descending order in PHP, we use the rsort() function.
Let's say we have an array of names below:
$class= array('Mike', 'Bob', 'Steve', 'Craig', 'Richard', 'Adam');
And now we want this array to be shown and ordered in descending order by name.
We use the rsort() function to put it in descending order.
The general form to put an array of strings in descending order is:
rsort($array_name);
For the above array we created, the code to put it in descending order is:
rsort($class);
PHP Output
Steve Richard Mike Craig Bob Adam
HTML Comment Box is loading comments...