I asked a very similar question a while back and I was wondering if correctly sorting an array with UTF-8 chars got a little easier with the new improvements of PHP 5.3+.
The solution provided in my previous question works, but I’m looking for a universal solution; one that doesn’t depend on the locale specified – kind of what MySQL does with the UTF-8 collation.
Thanks in advance!
Short answer is: you do need to be aware of the locale.
Don’t confuse the charset with the locale sorting rules. UTF-8 is just a way to encode Unicode characters: it doesn’t imply anything about how you handle sorting, capitalization, etc.
I’ll put a simple example. The Spanish language has two collations: traditional (where “ch” is considered a letter) and modern (where “ch” are two letters). In traditional collation you sort this way:
In modern collation you’d sort this way:
This is the same in UTF-8, Latin1, Latin9, cp850 or whatever: the encoding is not relevant.