我有持有西班牙语言的名称的数组:排序有特殊字符数组在PHP
$lang["ko"] = "coreano"; //korean
$lang["ar"] = "árabe"; //arabic
$lang["es"] = "español"; //spanish
$lang["fr"] = "francés"; //french
我需要订购阵列并保持索引关系,所以我用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);
预期产出将是这个顺序:
- 阵列([AR] => ARABE [KO] => coreano [ES] =>西班牙语[FR] =>八方资源)
然而,这是我收到什么:
- 阵列([KO] => coreano [ES] =>西班牙语[FR] =>八方资源[AR] => ARABE)
我缺少的东西?感谢您的反馈意见! (我的服务器使用的PHP版本5.2.13)
狂猜:可能是因为'c'在'á'之前? –
这就是我使用SORT_LOCALE_STRING的原因。 'á'应该在'a'之后和'c'之前。 – andufo
好吧,祝你好运:) –