Home  >  Article  >  Backend Development  >  PHP array sorted by Chinese Pinyin

PHP array sorted by Chinese Pinyin

不言
不言Original
2018-04-13 13:55:063117browse

The content shared with you in this article is about sorting PHP arrays according to Chinese pinyin. It has a certain reference value. Friends in need can refer to it


<?php

$str = "我们可以在浏览器中看到,当鼠标移到元素上时,元素开始向右移动,开始比较慢,之后则比较快,移开时按原曲线回到原点。";

$len = mb_strlen($str);
$sta = [];
for($i = 0; $i<$len; $i++){
    $tmp = mb_substr($str,$i,1);
    if($tmp != " "){
        array_push($sta,$tmp);
    }
}

//将中文字符转换成gbk编码,必须先将数组转换为字符串,然后转换编码,最后将字符串反转成数组
$sta = eval(&#39;return &#39;.mb_convert_encoding(var_export($sta,true), "gbk","utf-8").";");
//按数组值进行排序
sort($sta);
//将中文字符转换成utf-8编码
$sta = eval(&#39;return &#39;.mb_convert_encoding(var_export($sta,true), "utf-8", "gbk").";");

var_dump($sta);

Related Recommended:

How to deal with PHP array problems



The above is the detailed content of PHP array sorted by Chinese Pinyin. For more information, please follow other related articles on the PHP Chinese website!

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
Previous article:php Restful API exampleNext article:php Restful API example