PHP Array KEYS Sorting Function

What is krsort() Function?


The "krsort()" function can sort an array by keys in reverse order.



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 :

$b=array("1"=>"Grapes","2"=>"Apple","3" =>"Cherry");
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".

PHP Topics

Ask Questions

Ask Question