且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在PHP中对UTF-8字符串数组进行排序?

更新时间:2023-11-25 10:04:28

intl 捆绑在一起从PHP 5.3和使用PHP,它仅支持UTF-8 .

intl comes bundled with PHP from PHP 5.3 and it only supports UTF-8.

在这种情况下,您可以使用整理器:

You can use a Collator in this case:

$array = array('Borgloon','Thuin','Lennik','Éghezée','Aubel');
$collator = new Collator('en_US');
$collator->sort($array);
print_r($array);

输出:

Array
(
    [0] => Aubel
    [1] => Borgloon
    [2] => Éghezée
    [3] => Lennik
    [4] => Thuin
)