php中文多音字排序

WBOY
Release: 2016-06-06 20:40:19
Original
1446 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
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!