Php Array Element Reverse order Sort Function

What is rsort Function?


The "rsort" function sorts an array elements in reverse order.



In the above syntax keys of the specified "array" will be changed. The parameter "sorttype" specifies the type in which to be sorted, for example "SORT_REGULAR", is the default type, "SORT_NUMERIC", treat values numerically, "SORT_STRING", treat values as strings, "SORT_LOCALE_STRING", treat values as string based on local settings.

Example :

$b=array("a"=>"Grapes","b"=>"Apple","c" =>"Cherry");
Result :

[0] => Cherry
[1] => Apple
[2] => Grapes

In the above example the array "$b" is sorted in the reverse order,and the keys are changed. Now displays the values in reverse order.

PHP Topics

Ask Questions

Ask Question