My data source is in utf8 format, but I need to sort the data. Since it is Chinese, I converted it to gbk or gbk2312, but some inaccuracies occurred in the sorting
I sorted using the array_multi_sort method of php
Such a problem will occur in the sorting results
The data in the black box is obviously incorrect in descending order of pinyin. However, the subsequent data are all appropriate. I don’t know the reason for this? Or is it that the gbk library is not complete enough?
Add a test code
<code>$array = array("鹭","昊","瀚","骅","众","怡","萃","重","恺","鑫"); foreach($array as $val){ $newArr[] = iconv('utf8','GBK',$val); } array_multisort($newArr,SORT_DESC,SORT_FLAG_CASE ); echo "<pre class="brush:php;toolbar:false">"; print_r($newArr); die;</code>
My data source is in utf8 format, but I need to sort the data. Since it is Chinese, I converted it to gbk or gbk2312, but some inaccuracies occurred in the sorting
I sorted using the array_multi_sort method of php
Such a problem will occur in the sorting results
The data in the black box is obviously incorrect in descending order of pinyin. However, the subsequent data are all appropriate. I don’t know the reason for this? Or is it that the gbk library is not complete enough?
Add a test code
<code>$array = array("鹭","昊","瀚","骅","众","怡","萃","重","恺","鑫"); foreach($array as $val){ $newArr[] = iconv('utf8','GBK',$val); } array_multisort($newArr,SORT_DESC,SORT_FLAG_CASE ); echo "<pre class="brush:php;toolbar:false">"; print_r($newArr); die;</code>
If the sorting result is not necessarily accurate according to the pinyin of Chinese characters, you can also sort according to the ascii
of Chinese characters, but the program complexity will increase. If your classification data is read from the database, you can try adding a sort field in the database