PHP krsort() Function is used to sort associative array in descending order according to the key. An krsort() function is built-in function in PHP.
Syntax :
krsort(array $array , $sort_type = SORT_REGULAR);
Parameter,
$array : Required. It is input array.
$sort_type : Optional. $sort_type may be used to modify the sorting behavior using below values.
- SORT_REGULAR - Default. Compare items normally (don't change types).
- SORT_NUMERIC - Compare items numerically.
- SORT_STRING - Compare items as strings.
- SORT_LOCALE_STRING - Compare items as strings that based on current locale.
- SORT_NATURAL - Compare items as strings using natural ordering.
- SORT_FLAG_CASE - It can be combined with SORT_STRING or SORT_NATURAL to sort strings case-insensitively.
Return Values :
It returns true on success or false on failure. A krsort() Function sorts an associative array in reverse order according to the key.
Let's see below example to understand php krsort() Function in details.
Comments