My code - short and easy:
setlocale(LC_ALL,'de_DE');
$tosort = ["Österreich","Indien","Deutschland","Vereinigtes Königreich","Zimbabwe"];
asort($tosort,SORT_LOCALE_STRING);
var_dump($tosort);
Result:
array(5) { [2]=> string(11) "Deutschland" [1]=> string(6) "Indien" [3]=> string(23) "Vereinigtes Königreich" [4]=> string(8) "Zimbabwe" [0]=> string(11) "Österreich" }
Expected Result:
array(5) { [2]=> string(11) "Deutschland" [1]=> string(6) "Indien" [3]=> string(11) "Österreich"[4]=> string(23) "Vereinigtes Königreich" [0]=> string(8) "Zimbabwe" }
Docs: http://php.net/manual/de/function.sort.php
Problem: The string is not sorted locally, even though I specifically did setlocale before the sorting. What is going wrong here and how might I solve this? The Ö Umlaut is expected to come directly between the O in the alphabet. What might go wrong here?