php按中文排序,php按照中文首字母排序

1> 网络上很多php的工具类可以将汉字转为拼音;

2> 将拼音进行排序即可

另一种则是类似mysql转码方式:

1 foreach ($array as $key=>$value)

2 {

3 $new_array[$key] = iconv('UTF-8', 'GBK', $value);

4 } 1 foreach ($array as $key=>$value)

2 {

3 $new_array[$key] = iconv('UTF-8', 'GBK', $value);

4 }

5 asort($new_array);

6 foreach ($new_array as $key=>$value)

7 {

8 $array[$key] = iconv('GBK', 'UTF-8', $value);

9 }

5 asort($new_array);

6 foreach ($new_array as $key=>$value)

7 {

8 $array[$key] = iconv('GBK', 'UTF-8', $value);

9 }

综合案列

//按中文首字母排序

function orderByName($userName,$order='asc',$key='jlname'){

foreach($userName as $name){

if(is_array($name))$char = getFirstChar($name[$key]);

elseif(is_string($name))$char= getFirstChar($name);

$nameArray = array();//将姓名按照姓的首字母与相对的首字母键进行配对

if(count($charArray[$char])!=0)$nameArray = $charArray[$char];

array_push($nameArray,$name);

$charArray[$char] = $nameArray;

}

if(strtolower($order)=='asc')ksort($charArray);elseif(strtolower($order)=='desc')krsort($charArray);

$newarr = array();

$i=0;

foreach($charArray as $ck=&g

你可能感兴趣的:(php按中文排序)