1,preg_match("/^[a-zA-Z]+(.*)?$/", $country) // 正则匹配,支持输入英文,只要一个字母为英文即可
2,preg_match("/^[a-zA-Zs]+$/", $country) // 正则匹配,支持输入英文,纯英文
3、ksort根据key值对关联字段进行升序排序
4.sort对索引数组进行逆序排序(排序顺序:数字AZ az其他【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);