PHP krsort() Function
Example
Sort an associative array in descending order by key name:
<?php $age=array("Bill"=>"60","Steve"=>"56","mark"=>"31"); krsort($age); ?>
Definition and Usage
The krsort() function sorts an associative array in descending order by key name.
Tip:Please use ksort() The function sorts an associative array in ascending order by key name.
Tip:Please use arsort() The function sorts an associative array in descending order by key value.
Syntax
krsort(array,sortingtype);
Parameters | Description |
---|---|
array | Required. Specifies the array to be sorted. |
sortingtype |
Optional. Specifies how to sort the elements/items of the array. Possible values:
|
Description
The krsort() function sorts an array in reverse order by key, keeping the original keys for the array values.
The optional second parameter includes additional sorting flags.
Returns TRUE if successful, FALSE otherwise.
Technical Details
Return Value: | Returns TRUE on success, FALSE on failure. |
PHP Version: | 4+ |