In this tutorial we will learn How to Sort array in descending order with PHP, We can use PHP rsort() function to sort any php array in descending order.
Table of Contents
PHP rsort() function
PHP rsort() function sorts an indexed or numerical array in descending order.
The rsort() function takes two parameters, array and sorttype value.
rsort() function is supported in PHP4+ versions.
Sorting array in descending numerical order
<?php
$array=array(123,10,43,98);
rsort($array);
print_r($array);
?>
Sorting array in descending alphabetical order
<?php
$array=array("HTML","PHP","CSS","JavaScript");
rsort($array);
print_r($array);
?>