Sort an associative array in descending order based on the key.
| <?php $age=array(“Peter”=>“35”,“Ben”=>“37”,“Joe”=>“43”); krsort($age); ?> |
The krsort() function sorts an associative array in descending order based on the key.
Tip: Use the ksort() function to sort an associative array in ascending order by key.
Tip: Use the arsort() function to sort an associative array in descending order by value.
| krsort(array, sorttype) |
|
Parameter |
Description |
|
array |
Required. Specifies the array to be sorted |
|
sorttype |
Optional. Specifies how to compare the array elements/items. Possible values are:
|
|
Return Value: |
Returns |
|
PHP Version: |
4+ |