Sort php array with accents

I use 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 an accent is used in a name, for example. Shiko, Aron, etc., These names are at the end. How can I sort it correctly?

+6
source share
1 answer

Use multibyte string functions. There is a function called strcoll that seems to fit your needs.

Additional Information:


EDIT: Added Peter working code below

 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']; } 
+11
source

Source: https://habr.com/ru/post/910437/


All Articles