讓資料按照中文筆劃排序

如何將中文字依照筆劃來排序? 透過中文處理函式,我們就可以計算出筆劃後把陣列中的中文資料進行排列,試試看吧!


<?php 
  include 'big5_func/big5_func.inc'; 
  function compare($s1, $s2){ 
    $n1 = big5_stroke($s1); 
    $n2 = big5_stroke($s2); 
    if($n1 == $n2) return 0; 
    return ($n1 < $n2) ? -1 : 1; 
  } 



  $string = array('驢子','史瑞克','白雪公主','長靴貓','小木偶','薑餅人','三隻小豬', 
                       '睡美人','壞皇后','七個小矮人','小美人魚','神仙教母'); 
  usort($string, 'compare'); 
  while (list($key, $value) = each($string)) { 
    echo "$key: $value<br>"; 
  } 
?>
Advertisements

One thought on “讓資料按照中文筆劃排序

  1. Pingback: 繁體中文筆劃排序 | BLACKBING

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s