PHP arsort() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The arsort() in PHP is used to sort an array according to values. It sorts in a way that relation between indices and values is maintained. By default it sorts in descending order of values. Syntax: bool arsort( $array, $sorting_type ) Parameters: This function accepts two parameters as mentioned above and described below: $array: This parameter specifies the array which to be sort. It is a mandatory parameter. $sorting_type: This parameter specifies name of a user-defined function which will be used to sort the keys of array $array. This comparison function must return an integer. Return Value: This function returns True on success or False on failure. Below programs illustrate the arsort() function in PHP. Program 1: php <?php // PHP program to illustrate // arsort() function // Input different array elements $arr = array("0" => "GeeksforGeeks", "1" => "Practice", "2" => "Contribute", "3" => "Java", "4" => "Videos", "5" => "Report Bug", "6" => "Article", "7" => "Sudo Placement" ); // Implementation of arsort() arsort($arr); // for-Loop for displaying result foreach ($arr as $key => $val) { echo "[$key] = $val"; echo"\n"; } ?> Output: [4] = Videos [7] = Sudo Placement [5] = Report Bug [1] = Practice [3] = Java [0] = GeeksforGeeks [2] = Contribute [6] = Article Program 2: php <?php // PHP program to illustrate // arsort() function // Input different array elements $arr = array("a" => 11, "b" => 22, "d" => 33, "n" => 44, "o" => 55, "p" => 66, "p" => 77, "q" => 88, ); // Implementation of arsort() arsort($arr); // for-Loop for displaying result foreach ($arr as $key => $val) { echo "[$key] = $val"; echo"\n"; } ?> Output: [q] = 88 [p] = 77 [o] = 55 [n] = 44 [d] = 33 [b] = 22 [a] = 11 Related Articles: uksort() Function uasort() Function usort() Function Reference: https://www.php.net/manual/en/function.arsort.php Comment J jit_t Follow 0 Improve J jit_t Follow 0 Improve Article Tags : PHP PHP-array PHP-function Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like