PHP Array KEYS Sorting Function
What is krsort() Function?
Explanation
The "krsort()" function can sort an array by keys in reverse order.
Syntax:
krsort(array,sorttype)
In the above syntax "array" is the array to be sorted in the reverse order using the keys,"sorttype" specifies the type in which the sorting has to be performed, some of the parameters are "SORT_REGULAR",is the default type, "SORT_NUMERIC", treat the values numerically, "SORT_STRING", treat values as strings, "SORT_LOCALE_STRING", treat values as string based on local settings.
Example :
<?php
$b=array("1"=>"Grapes","2"=>"Apple","3" =>"Cherry");
krsort($b);
print_r($b);
?>
Result :
[3] => Cherry
[2] => Apple
[1] => Grapes
In the above example the array "$b" is sorted based on the keys in the reverse order, displays values starting from "Cherry".