我使用它根据姓氏排序:
usort($fb_friends['data'],"custom_sort"); function custom_sort($a,$b) { return $a['last_name']>$b['last_name']; } foreach($fb_friends['data'] as $friend) { echo '<br>'; echo $friend['name']; }
但是 – 当姓氏是重音时,例如Šiko,Áron等,这些名字都在最后.我怎样才能正确排序?
使用多字节字符串函数.有一个名为
strcoll
的功能似乎符合您的需求.
更多信息:
> On how to sort an array of UTF-8 strings
> How to sort an array of UTF-8 strings?
setlocale(LC_COLLATE,'sk_SK.utf8'); usort($fb_friends['data'],'custom_sort'); function custom_sort($a,$b) { return strcoll ($a['last_name'],$b['last_name']); } foreach ($fb_friends['data'] as $friend) { echo '<br>'; echo $friend['name']; }