Reputation: 978
I'm trying to sort an array of names alphabetically (Croatian in this case).
How can I get Đani
to show up before Derrick
?
$names = array(
"Đani", "Bill", "Dennis", "George", "Derrick"
);
sort($names);
print_r($names);
Upvotes: 2
Views: 1758
Reputation: 95252
You need to set the locale appropriately, probably like this:
setlocale(LC_ALL, 'hr_HR');
And then tell sort to honor the locale:
sort($names,SORT_LOCALE_STRING);
Upvotes: 5
Reputation:
If you can, you can import them into a MySQL table and use the ORDER BY
clause to sort, provided you set the right collation for the database/table.
I am sure that there are simpler solutions not requiring a RDMS though.
Take a look to that question as well: Natural sorting algorithm in PHP with support for Unicode?
Upvotes: 0