You are here: Home / Topics / How to sort elements of an array in descending order in PHP?

How to sort elements of an array in descending order in PHP?

Filed under: PHP on 2022-11-19 12:32:53

The below program is to sort elements of an array in descending order using PHP sort() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time.

sort() function in PHP


Example

<!DOCTYPE html>
<html>
<body>

<?php    
$numbers=array("100","160","20","67");    
rsort($numbers);  
foreach( $numbers as $n )    
{    
 echo "$n<br />";    
}    
?> 

</body>
</html>
 

Output

160
100
67
20

About Author:
V
Vinay Kumar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.