Definition
The arsort() function sorts an associative array in descending order, according to the value.
Syntax
arsort(array, sorttype)
Parameters
Parameter | Description |
---|---|
array |
Required. Specifies the array to sort. |
sorttype |
Optional. Possible values: 0 = SORT_REGULAR - Default. Compare items normally (don't change types)1 = SORT_NUMERIC - Compare items numerically2 = SORT_STRING - Compare items as strings3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale4 = SORT_NATURAL - Compare items as strings using natural ordering5 = SORT_FLAG_CASE - Can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively |
Example
<?php
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28);
arsort($ages);
print_r($ages);