Definition:
The arsort()
function sorts an associative array in descending order, according to the value.
The keys are preserved, i.e. the key-to-value mapping will remain unchanged by the sort operation.
arsort(array, sorttype)
Parameter | Description |
---|---|
array | Required. Specifies the array to sort |
sorttype | Optional. Specifies how to compare the array elements/items. Possible values:
|
Example : we can see below example Sort an associative array in descending order, according to the value:
Output :
Key=House, Value=33
Key=Designing, Value=27
Key=Web, Value=25
Tip: The arsort()
and asort()
functions mainly used for sorting associative arrays by value, whereas krsort()
and ksort()
functions used for sorting associative arrays by key.