Collator::asort() - Collator类
Collator::asort()
collator_asort
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Sort array maintaining index association
说明
面向对象风格publicCollator::asort(array &$arr[,int $sort_flag]): bool过程化风格
collator_asort(Collator$coll,array &$arr[,int $sort_flag]): bool
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. Array elements will have sort order according to current locale rules.
Equivalent to standard PHP asort().
参数
$collCollator object.
$arrArray of strings to sort.
$sort_flagOptional sorting type, one of the following:
Collator::SORT_REGULAR
- compare items normally(don't change types)Collator::SORT_NUMERIC
- compare items numericallyCollator::SORT_STRING
- compare items as strings
Default $sort_flag value is Collator::SORT_REGULAR
. It is also used if an invalid $sort_flag value has been specified.
返回值
成功时返回TRUE
,或者在失败时返回FALSE
。
范例
collator_asort()example
以上例程会输出:
array ( 'c' => '7', 'b' => '50', 'a' => '100', )array ( 'a' => '100', 'b' => '50', 'c' => '7', )
参见
- Collator constants
- collator_sort() Sort array using specified collator
- collator_sort_with_sort_keys() Sort array using specified collator and sort keys
For those of you who are looking for a way to integrate natural sorting with the UCA rules this hack seems to work: Output: Array ( [0] => 1 [1] => 100 [2] => al [3] => be [4] => Alpha [5] => Beta [6] => Álpha [7] => Àlpha [8] => Älpha [9] => かたかな [10] => img1.png [11] => img2.png [12] => img10.png [13] => img20.png )
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!