I am using this to sort according to last name:
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'];
}
But - when in last name is accent, e.g. Šiko, Áron, etc, these names are at the end. How can I sort it properly?
Use multi-byte string functions. There is a function called
strcoll
which seems to suit your needs.More info:
EDIT: added Peter's working code, below
What comes first?
This is defined by a Collation.
PHP has the Collator class for this: https://www.php.net/manual/en/class.collator.php
Example:
Returns:
Now with a Chinese collation
new Collator('zh')
:You can try it yourself here: https://3v4l.org/0vsBR
The first argument receives a locale. I couldn't find information about what locales are valid, it seems that different systems have different naming schemes for locales, but if you stick with RFC 1766 or ISO 639 you will be fine.