krsort() definition and usage
krsort() function sorts the array in reverse order by key, retaining the original keys for the array values.
The optional second parameter contains additional sorting flags.
If successful, return TRUE, otherwise return FALSE.
Syntax
krsort(array,sorttype) Parameter Description
array Required. Specifies the array to be sorted.
sorttype optional. Specifies how to arrange the values of an array. Possible values:
SORT_REGULAR - Default. Processed with their original type (without changing type).
SORT_NUMERIC - Handle values as numbers
SORT_STRING - Handle values as strings
SORT_LOCALE_STRING - Handle values as strings, based on local settings*.
*: This value is newly added in PHP 4.4.0 and 5.0.2. Prior to PHP 6, the system locale was used, which could be changed with setlocale(). Since PHP 6, the i18n_loc_set_default() function must be used.
Example
Copy code The code is as follows:
$my_array = array("a" => "Dog", "b" => "Cat", "c" = > "Horse");
krsort($my_array);
print_r($my_array);
?>
The above introduces the krsort of PHP array function sequence-sorts the element key names of the array in descending order and maintains the index relationship, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.