更新时间:2023-02-06 13:49:28
您需要的是排序但具有自定义比较功能(usort). 下面的代码可以完成它:
What you need is sort but with a custom comparison function (usort). The following code will get it done:
function myComparison($a, $b){
if(is_numeric($a) && !is_numeric($b))
return 1;
else if(!is_numeric($a) && is_numeric($b))
return -1;
else
return ($a < $b) ? -1 : 1;
}
$test = array("def", "yz", "abc", "jkl", "123", "789", "stu");
usort ( $test , 'myComparison' );