Home  >  Article  >  Backend Development  >  PHP array function sequence sort() sorts the element values ​​of the array in ascending order

PHP array function sequence sort() sorts the element values ​​of the array in ascending order

伊谢尔伦
伊谢尔伦Original
2016-11-25 13:58:30837browse

sort() definition and usage
sort() function sorts the values ​​of the given array in ascending order.

Note: This function assigns a new key name to the unit in the array. The original key name will be deleted.

Returns TRUE if successful, otherwise returns FALSE.

Syntax
sort(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

 "Dog", "b" => "Cat", "c" => "Horse"); 
sort($my_array); 
print_r($my_array); 
?>

Output:

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


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