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:

$colors = array("Red", "Orange", "Black", "White");

Sample Output:

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


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?

PHP: Tips of the Day

PHP: Extract numbers from a string

$str = 'In My Cart : 11 12 items';
preg_match_all('!\d+!', $str, $matches);