header('Content-Type: text/plain; charset=utf-8');
$arr = explode(' ', '1 11 111 112 12 121 122 a aa aaa aab ab aba abb 阿里 百度 中 中国 中国国 中国中 中中 中中国 中中中');
shuffle($arr); //打乱数组
//collator_sort(collator_create('zh_CN'), $arr);
//usort($arr, function($a, $b) { return strnatcmp($a, $b); });
usort($arr, function($a, $b) { return strcmp($a, $b); });
echo implode(' ',$arr);
exit();
?>
ls排序:
1 11 111 112 12 121 122 a aa aaa aab ab aba abb 阿里 百度 中 中国 中国国 中国中 中中 中中国 中中中
collator_sort(zh_CN)排序(类似Windows/Linux桌面文件管理器里的默认按名称上升排列):
1 11 12 111 112 121 122 a aa aaa aab ab aba abb 阿里 百度 中 中国 中国国 中国中 中中 中中国 中中中
strnatcmp排序:
1 11 12 111 112 121 122 a aa aaa aab ab aba abb 中 中中 中中中 中中国 中国 中国中 中国国 百度 阿里
strcmp排序:
1 11 111 112 12 121 122 a aa aaa aab ab aba abb 中 中中 中中中 中中国 中国 中国中 中国国 百度 阿里
使用strcmp字符串比较排序其实就已经能够满足你的需求.
strnatcmp自然排序跟strcmp字符串比较排序主要区别在于数字,strnatcmp处理后的数字元素是由小到大排序,存在大小关系.
而ICU扩展intl里的简体中文排序器collator_sort(zh_CN)排序主要能够根据汉字的拼音进行排序,比如Ali,Baidu,ZhongGuo.感兴趣还可以看下我的这篇文章 PHP利用ICU扩展intl快速实现汉字转拼音以及按拼音首字母分组排序 ,汉字转拼音就一个函数的事:
echo transliterator_transliterate('Any-Latin; Latin-ASCII; Upper()', '中华有为');
//输出 ZHONG HUA YOU WEI