首页 > 解决方案 > PHP:为什么标志 SORT_LOCALE_STRING 没有按预期工作?

问题描述

我的代码 - 简短易懂:

    setlocale(LC_ALL,'de_DE');
    $tosort = ["Österreich","Indien","Deutschland","Vereinigtes Königreich","Zimbabwe"];
    asort($tosort,SORT_LOCALE_STRING);
    var_dump($tosort);

结果:

数组(5){ [2]=> 字符串(11)“德国”[1]=> 字符串(6)“印度”[3]=> 字符串(23)“Vereinigtes Königreich”[4]=> 字符串(8 ) "津巴布韦" [0]=> 字符串(11) "Österreich" }

预期结果:

数组(5){ [2]=> 字符串(11)“德国”[1]=> 字符串(6)“印度”[3]=> 字符串(11)“Österreich”[4]=> 字符串(23) "Vereinigtes Königreich" [0]=> string(8) "津巴布韦" }

文档: http: //php.net/manual/de/function.sort.php

问题:字符串没有在本地排序,即使我在排序之前专门做了 setlocale。这里出了什么问题,我该如何解决?预计 Ö 变音符号将直接出现在字母表中的 O 之间。这里可能出了什么问题?

标签: phpsortingutf-8localization

解决方案


推荐阅读