相关疑难解决方法(0)

在PHP中使用特殊字符对数组进行排序

我有一个数组,其中包含西班牙语的语言名称:

$lang["ko"] = "coreano"; //korean
$lang["ar"] = "árabe"; //arabic
$lang["es"] = "español"; //spanish
$lang["fr"] = "francés"; //french
Run Code Online (Sandbox Code Playgroud)

我需要对数组进行排序并维护索引关联,因此我将asort()SORT_LOCALE_STRING一起使用

setlocale(LC_ALL,'es_ES.UTF-8'); //this is at the beginning (config file)
asort($lang,SORT_LOCALE_STRING);
print_r($lang);
Run Code Online (Sandbox Code Playgroud)

预期的输出将按以下顺序排列:

  • 数组([ar] =>árabe[ko] => coreano [es] =>español[fr] =>francés)

但是,这是我收到的:

  • 数组([ko] => coreano [es] =>español[fr] =>francés[ar] =>árabe)

我错过了什么吗?感谢您的反馈意见!(我的服务器使用PHP版本5.2.13)

php setlocale asort

12
推荐指数
1
解决办法
9774
查看次数

标签 统计

asort ×1

php ×1

setlocale ×1