Given the following array:
$foo = ["a", "B", "æ", "Æ", "c", "A", "b", "C", "1"];
Then I set the locale with setlocale(LC_ALL, ['nb_NO.UTF-8', 'no_NO.UTF-8']);
and run the array through sort($foo, SORT_LOCALE_STRING)
.
In Ubuntu, the sorted array will then look like:
[
0 => '1',
1 => 'A',
2 => 'a',
3 => 'B',
4 => 'b',
5 => 'C',
6 => 'c',
7 => 'Æ',
8 => 'æ',
]
While on Mac (OS X) I get:
[
0 => '1',
1 => 'A',
2 => 'B',
3 => 'C',
4 => 'a',
5 => 'b',
6 => 'c',
7 => 'Æ',
8 => 'æ',
]
It seems OS X wants to sort strings starting with capital letters by themselves(ABC
, then abc
), while I would just like them to be together (AaBbCc
).
Is there any way of having them sort the arrays the same way in PHP, or would I have to write a custom sorting method, using one of the u*sort()
methods instead?
Edit: seems to be quite similar to the question this is marked as a duplicate of. Altough OS X still seems to sort upper- and lower case letters after each other instead of mixing them, it is fixable by adding strtolower()
to the sorting function.