The PHP arsort function is used to sort the elements in the array in descending order, if the sort succeeds returns True, otherwise returns false, this article explains the basic syntax of the Arsort function and the use of examples, the need for friends can refer to the following
Arsort the array in descending order and maintains the index relationship.
Basic syntax
BOOL Arsort (array & $array [, int $sort _flags = sort_regular])
This function sorts the arrays in descending order, the index of the array remains and the cell is associated.
The Arsort function is primarily used to sort the associative arrays that are important for the cell order.
Parameter description:
Parameters |
Description |
Array |
Necessary. The input array. |
Sort_flags |
Optional. Specifies how to arrange the elements/items of an array. Possible values:
0 = sort_regular-default. Arrange each item in the usual order (standard ASCII, no change type)
1 = sort_numeric-Each item is treated as a number.
2 = sort_string-Each item is treated as a string.
3 = sort_locale_string-handles each item as a string, based on the current locale (can be changed by setlocale ()).
4 = sort_natural-handles each item as a string, using a natural sort similar to Natsort ().
5 = sort_flag_case-You can sort strings by combining (bitwise OR) sort_string or sort_natural, not case-sensitive.
|
Description
The Arsort () function reverses the array and maintains the index relationship. It is primarily used to sort the associative arrays that are important for the cell order.
The Second optional parameter contains an additional sort ID.
return value
Returns TRUE on success, or FALSE on failure.
Instance:
<?php$age=array ("Bill" = "the", "Steve" and "the", "Mark" = "31"); Arsort ($age);?