PHP arsort()Functions
Examples
Sort the associative array by values in descending order:
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
arsort($age);
?>
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
arsort($age);
?>
Run example »
Definition and Usage
The arsort() function sorts an associative array by values in descending order.
Tip:Please useasort()function to sort an associative array by values in ascending order.
Tip:Please usekrsort()function to sort an associative array by keys in descending order.
Syntax
arsort(array,sortingtype);
| Parameter | Description |
|---|---|
| array | Required. Specifies the array to be sorted. |
| sortingtype | Optional. Specifies how to arrange the array's elements/items. Possible values:
|
Technical Details
| Return Value: | Returns TRUE on success, or FALSE on failure. |
|---|---|
| PHP Version: | 4+ |
Complete PHP Array Reference Other Extensions