And*_* SK 12 php setlocale asort
我有一个数组,其中包含西班牙语的语言名称:
$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)
预期的输出将按以下顺序排列:
但是,这是我收到的:
我错过了什么吗?感谢您的反馈意见!(我的服务器使用PHP版本5.2.13)
lor*_*o-s 13
尝试按透明名称排序:
function compareASCII($a, $b) {
$at = iconv('UTF-8', 'ASCII//TRANSLIT', $a);
$bt = iconv('UTF-8', 'ASCII//TRANSLIT', $b);
return strcmp($at, $bt);
}
uasort($lang, 'compareASCII');
print_r($lang);
Run Code Online (Sandbox Code Playgroud)