如何考虑本地化对数组进行排序? [英] How to sort an array considering localization?
本文介绍了如何考虑本地化对数组进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试按字母顺序对名称数组进行排序(在这种情况下为克罗地亚语).
I'm trying to sort an array of names alphabetically (Croatian in this case).
如何让Đani
出现在Derrick
之前?
$names = array(
"Đani", "Bill", "Dennis", "George", "Derrick"
);
sort($names);
print_r($names);
推荐答案
您需要适当地设置语言环境,可能是这样的:
You need to set the locale appropriately, probably like this:
setlocale(LC_ALL, 'hr_HR');
然后告诉sort遵守区域设置:
And then tell sort to honor the locale:
sort($names,SORT_LOCALE_STRING);
这篇关于如何考虑本地化对数组进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文