Reputation: 3171
I have a list of Icelandic names that I need to sort, e.g.
["Árni", "Anna", "Birkir"]
The correct icelandic order would have Á
between A
and B
.
If I try to sort via Collator, I get an error message that the fallback was used (= Icelandic is not installed? [How] can I install additional languages for that?)
If I however try to sort via strnatcmp
after setlocale(LC_COLLATE, 'is_IS')
, it returns Á between Y and Þ (which is wrong).
How can I get correctly sorted Icelandic names without programming it myself?
Upvotes: 0
Views: 86
Reputation: 7693
You can use the Collator
class (if available).
$arr = ["Árni", "Anna", "Birkir"];
$collator = new Collator('is_IS');
$collator->sort($arr);
var_dump($arr);
Output:
array(3) { [0]=> string(4) "Anna" [1]=> string(5) "Árni" [2]=> string(6) "Birkir" }
With var_dump(class_exists('Collator', false));
you can check if the class is available.
Upvotes: 1