简体   繁体   中英

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.

Anyway, the alphabetizing worked perfectly, except on a few French names that began with a lowercase "d", eg. "de Toussard". It dumped those names at the very end, after names beginning with "Z".

When I capitalize the "d" it works fine.

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. So if you need $arr['a'] from your example to stay untouched do

$lowercase = array_map('strtolower', $arr['a']);

and then

array_multisort($lowercase, SORT_ASC, SORT_STRING, $arr['b']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM