Home>Article>Backend Development> PHP multidimensional array PHP array function sequence asort - Sort the element values of the array in ascending order, maintaining the index relationship
asort() Definition and Usage
asort() function sorts an array and maintains index relationship. Mainly used for sorting associative arrays where the order of cells is important.
The optional second parameter contains additional sorting flags.
Returns TRUE if successful, otherwise returns FALSE.
Syntax
asort(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 codeThe code is as follows:
$my_array = array("a" => "Dog", "b" => "Cat", "c" = > "Horse");
asort($my_array);
print_r($my_array);
?>
The above introduces the PHP multi-dimensional array PHP array function sequence asort - sort the element values of the array in ascending order, maintaining the index relationship, including the content of PHP multi-dimensional arrays, I hope it will be helpful to friends who are interested in PHP tutorials.