Home >Backend Development >PHP Tutorial >php中文多音字排序

php中文多音字排序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:40:191532browse

例如给省份排序,“重庆”本来念做“chongqing”,但是php自带的排序识别成了“zhongqing”,所以排序结果就不对了。

请问有没有解决这种问题的简单方法?

回复内容:

例如给省份排序,“重庆”本来念做“chongqing”,但是php自带的排序识别成了“zhongqing”,所以排序结果就不对了。

请问有没有解决这种问题的简单方法?

<code>function sortFunction($str1, $str2) {
    return strcmp($str1[1], $str2[1]);
}   

$arr = array(
        array("重庆", "chongqing"),
        array("北京", "beijing"),
        array("天津", "tianjin"),
        array("大连", "dalian"),
);

usort($arr, "sortFunction");

// $sortedArr是排序后的数组
$sortedArr = array();
foreach ($arr as $item) {
    $sortedArr[] = $item[0];
}
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn