English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The asort() function sorts the array and maintains the index relationship
asort(array &$array[, int $sort_flags = SORT_REGULAR]);
This function sorts the array and keeps the index associated with the unit. It is mainly used to sort combined arrays where the order of the units is very important.
Returns TRUE on success, or FALSE on failure.
Number | Parameters and Description |
---|---|
1 | array (required) It specifies an array. |
2 | sort_flags (optional) You can change the sorting method using the optional parameter sort_flags. |
The array fruits is sorted in alphabetical order, and the relationship between the index and the unit remains unchanged.
<?php $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); asort($fruits); foreach ($fruits as $key => $val) { echo "$key = $val\n"; } ?>Test to see‹/›
Output Result:
c = apple b = banana d = lemon a = orange