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

php中文多音字排序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:40:19
Original
1541 people have browsed it

例如给省份排序,“重庆”本来念做“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>
Copy after login
Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template