0

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?

Blackbam
  • 17,496
  • 26
  • 97
  • 150
  • I modified the example in the duplicate and it produced what you were asking for https://3v4l.org/ScXfi – Machavity Jun 26 '18 at 17:24
  • Also, the `Ö` is a much higher UTF-8 character number than A-Z. That's why it appears last in a basic sort – Machavity Jun 26 '18 at 17:26
  • Ok thank you. The Collator seems to throw a fatal error if on PHP 7.0.1 I guess that has something to do with the PHP intl package? http://php.net/manual/en/book.intl.php – Blackbam Jun 26 '18 at 18:47
  • 1
    Looks like it is a separate package in most distros. [The comments on the install page should help you get the right package](http://php.net/manual/en/intl.installation.php) – Machavity Jun 26 '18 at 18:59

0 Answers0