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