版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gaokcl/article/details/83095256
1,preg_match("/^[a-zA-Z]+(.*)?$/", $country) // 正则匹配,支持输入英文,只要一个字母为英文即可
2,preg_match("/^[a-zA-Z\s]+$/", $country) // 正则匹配,支持输入英文,纯英文
3,ksort 按照键名对关联数组进行升序排序
4,sort 对索引数组进行升序排序 ( 排序顺序: 数字 A-Z a-z 其他 [ PHP函数自带属性 ] )
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// 数组 代替 MySQL查询数据(测试用)
$nations = array("Australia","Canada","Poland","eqeq","444","5555","测试","asss");
// 按照 A-Za-z(不区分大小写,排序:Aaaa aeedd) + 数字 + 其他(中文,特殊字符等) 排序
$sort_country_arr = $country_arr = array();
foreach ($nations as $v) {
if (preg_match("/^[a-zA-Z]+(.*)?$/", $v)) { // 英文
$sort_country_arr['english'][strtoupper($v)] = $v;
} elseif (is_numeric($v)) { // 数字
$sort_country_arr[] = $v;
} else { // 中文 或者 其他
$sort_country_arr[] = $v;
}
}
$country_en = $sort_country_arr['english'];
ksort($country_en);
unset($sort_country_arr['english']);
$country_arr = $country_en + $sort_country_arr;
$smarty->assign('nations', $country_arr);