[英]array_multisort() alphabetizing issues with lowercase letters
I have a database of individuals, and needed to sort them alphabetically by last name. 我有一个个人数据库,需要按姓氏的字母顺序对它们进行排序。 Basically:
基本上:
array_multisort($arr['a'],SORT_ASC,$arr['b'], etc...)
I had initially put in a SORT_STRING after the SORT_ASC, but it didn't seem to make a difference for me, so I dropped it. 我最初是在SORT_ASC之后输入SORT_STRING,但对我来说似乎没有什么不同,所以我删除了它。
Anyway, the alphabetizing worked perfectly, except on a few French names that began with a lowercase "d", eg. 无论如何,按字母顺序排列的效果很好,除了一些以小写的“ d”开头的法语名称(例如)。 "de Toussard".
“德·图萨德”。 It dumped those names at the very end, after names beginning with "Z".
它以“ Z”开头的名称在最末尾转储了这些名称。
When I capitalize the "d" it works fine. 当我将“ d”大写时,它可以正常工作。
Anything I can do to make it work regardless? 无论如何,我可以做些什么来使其正常工作?
As explained in this example http://php.net/manual/en/function.array-multisort.php#example-6112 you should sort by a lowercase copy of the original array. 如本示例http://php.net/manual/en/function.array-multisort.php#example-6112中所述,您应按原始数组的小写副本进行排序。 So if you need
$arr['a']
from your example to stay untouched do 因此,如果您需要示例中的
$arr['a']
保持原样,
$lowercase = array_map('strtolower', $arr['a']);
and then 接着
array_multisort($lowercase, SORT_ASC, SORT_STRING, $arr['b']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.