English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The arsort() function sorts an array in reverse order while preserving the index relationship
arsort(array &$array[, int $sort_flags = SORT_REGULAR]);
This function sorts the array while keeping the index relationship between the array and the elements.
主要用于对那些单元顺序很重要的组合数组进行排序。
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 reverse alphabetical order, and the index relationship of the elements remains unchanged.
<?php $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); arsort($fruits); foreach ($fruits as $key => $val) { echo "$key = $val\n"; } ?>Test and See‹/›
Output Result:
a = orange d = lemon b = banana c = apple