php 数组中文排序

一、mysql数据库处理

 select * from activity_channel order by convert(channel_name using gbk);

二、php处理

function cmp($a, $b) {
 $a["fruit"] = iconv("UTF-8", "gb2312", $a["fruit"]);
 $b["fruit"] = iconv("UTF-8", "gb2312", $b["fruit"]);
 return strcmp($a["fruit"], $b["fruit"]);
}
$fruits[0]["fruit"] = "比较";
$fruits[1]["fruit"] = "阿拉丁";
$fruits[2]["fruit"] = "阿猫";
print_r($fruits);
usort($fruits, "cmp");
while (list($key, $value) = each($fruits)) {
 echo "$fruits[$key]: " . $value["fruit"] . "\n";
}

发表评论