Home  >  Article  >  Backend Development  >  PHP array PHP array function sequence rsort - Sort the element values ​​of the array in descending order

PHP array PHP array function sequence rsort - Sort the element values ​​of the array in descending order

WBOY
WBOYOriginal
2016-07-29 08:47:031272browse

rsort() definition and usage
rsort() function sorts the elements of the array in reverse order by key value. Basically the same function as arsort().
Note: This function assigns new key names to cells in array. This will delete the original keys rather than just reorder them.
Returns TRUE if successful, otherwise returns FALSE.
The optional second parameter contains additional sorting flags.
Syntax
rsort(array,sorttype) Parameter Description
array Required. The input array.
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");
rsort($my_array);
print_r($my_array);
?>


Output:
Array
(
[0] => Horse
[1] => Dog
[2] => Cat
)

The above introduces the PHP array PHP array function sequence rsort - Sort the element values ​​of the array in descending order, including PHP array content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn