Is it possible to sort an array with Unicode / UTF-8 characters in PHP using a natural order algorithm? For example (the order in this array is correctly ordered):
$array = array
(
0 => 'Agile',
1 => 'Ágile',
2 => 'Àgile',
3 => 'Âgile',
4 => 'Ägile',
5 => 'Ãgile',
6 => 'Test',
);
If I try with asort($array) I get the following result:
Array
(
[0] => Agile
[6] => Test
[2] => Àgile
[1] => Ágile
[3] => Âgile
[5] => Ãgile
[4] => Ägile
)
And using natsort($array):
Array
(
[2] => Àgile
[1] => Ágile
[3] => Âgile
[5] => Ãgile
[4] => Ägile
[0] => Agile
[6] => Test
)
How can I implement a function that returns the correct result order (0, 1, 2, 3, 4, 5, 6) under PHP 5? All the multi byte string functions (mbstring, iconv, ...) are available on my system.
EDIT: I want to natsort() the values, not the keys - the only reason why I'm explicitly defining the keys (and using asort() instead of sort()) is to ease the job of finding out where the sorting of unicode values went wrong.