目前,我的数组按字符串长度排序。但是,当字符串长度相等时,如何按值排序?
例如,我当前的代码:
$array = array("A","BC","AA","C","BB", "B");
function lensort($a,$b){
return strlen($a)-strlen($b);
}
usort($array,'lensort');
print_r($array);
输出:
Array
(
[0] => C
[1] => A
[2] => B
[3] => BB
[4] => AA
[5] => BC
)
但是,我希望它按以下排序:
Array
(
[0] => A
[1] => B
[2] => C
[3] => AA
[4] => BB
[5] => BC
)