PHP array sorted by Chinese Pinyin

不言
Release: 2023-03-23 17:34:02
Original
3125 people have browsed it

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);
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!