Home > Backend Development > PHP Tutorial > array_multisort()二维数组排序中文值

array_multisort()二维数组排序中文值

WBOY
Release: 2016-06-06 20:20:08
Original
1897 people have browsed it

二维数组排序,需要排序的字段是中文,怎么实现?
我现在是把中文字段转化成了拼音,用拼音排序的,有没有更科技高效的办法。

回复内容:

二维数组排序,需要排序的字段是中文,怎么实现?
我现在是把中文字段转化成了拼音,用拼音排序的,有没有更科技高效的办法。

首先吧,要对array_multisort()理解,可看手册
(sort_array, sorting type, $source_array) 排序数组,排序方式,排序的源数组
其次,UTF-8 转成 GBK2312 才能实现以拼音顺序。上代码吧,感受一下。

<code>    header("Content-type:text/html;charset=utf-8");

    $array = array(
        array("新浪", 'x'),
        array("百度", 'b'),
        array("腾讯", 't')
    );
    //转换编码构造
     foreach ($array as $key => $item) {
         $sort_array[] = iconv("UTF-8", "GB2312", $item[0]);
     }
     //调用函数,注意参数相关写法
     array_multisort($sort_array, SORT_STRING, $array);
     var_dump($array);</code>
Copy after login
Related labels:
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