Sort elements in an array in descending order PHP program

PHP Functions For Sorting Array In Descending Order: rsort().
The rsort() function sorts an indexed array in descending order.

Sort the elements of the $MyArray array in descending numerical order:

<?php
    $MyArray=array(8, 20, 4, 100, 50, 6, 9, 11, 22, 5);
    rsort($MyArray);
    print_r($MyArray);
?>

Output:

Array ( [0] => 100 [1] => 50 [2] => 22 [3] => 20 [4] => 11 [5] => 9 [6] => 8 [7] => 6 [8] => 5 [9] => 4 ) 

Sort the elements of the $MyArray array in descending alphabetical order:

<?php
    $MyArray=array("PHP", "HTML", "CSS", "JavaScript", "Mysql", "Java", "AngularJs", "WordPress");
    rsort($MyArray);
    print_r($MyArray);
?>

Output:

Array ( [0] => WordPress [1] => PHP [2] => Mysql [3] => JavaScript [4] => Java [5] => HTML [6] => CSS [7] => AngularJs ) 

Sorting using krsort() – Sort an array by key in reverse order

<?php
    $MyArray=array("PHP", "HTML", "CSS", "JavaScript", "Mysql", "Java", "AngularJs", "WordPress");
    krsort($MyArray);
    print_r($MyArray);
?>

Output:

Array ( [7] => WordPress [6] => AngularJs [5] => Java [4] => Mysql [3] => JavaScript [2] => CSS [1] => HTML [0] => PHP ) 
Mukesh Jakhar - PHP Web Developer
Mukesh Jakhar

This is Mukesh Jakhar. I’m a professional web developer with 3+ years experience. I am always ready for freelance work and i am writing blogs in my free time. I love to learn new technologies and share with others.

I founded PHPKIDA in September 2015. The focus of this website to provide web development tutorials of PHP, WordPress, CodeIgniter, Jquery, MySQL, HMTL, CSS etc and sharing solution to problems which i already solved.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.