w3resource
php Programming Exercies

PHP Array Exercises : Sort an array in reverse order

PHP Array: Exercise-28 with Solution

Write a PHP script to sort an array in reverse order (highest to lowest).

Sample Solution:

PHP Code:

<?php
$colors = array("Red", "Orange", "Black", "White");
rsort($colors);
print_r($colors);
?>

Sample Output:

Array                                                       
(                                                           
    [0] => White                                            
    [1] => Red                                              
    [2] => Orange                                           
    [3] => Black                                            
)

Flowchart:

Flowchart: PHP - Sort an array in reverse order

PHP Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a PHP function to generate a random password (contains uppercase, lowercase, numeric and other) using shuffle() function.
Next: Write a PHP program to generate an array with a range taken from a string.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming