6.5.13 PHP數(shù)組的排序函數(shù)2
數(shù)組的排序函數(shù)
sort -- 對數(shù)組排序(升序)
rsort -- 對數(shù)組逆向排序(降序)
ksort -- 對數(shù)組按照鍵名排序
krsort -- 對數(shù)組按照鍵名逆向排序
asort -- 對數(shù)組進行排序并保持索引關系(關聯(lián)數(shù)組排序)
arsort -- 對數(shù)組進行逆向排序并保持索引關系
natsort -- 用“自然排序”算法對數(shù)組排序
natcasesort -- 用“自然排序”算法對數(shù)組進行不區(qū)分大小寫字母的排序
usort -- 使用用戶自定義的比較函數(shù)對數(shù)組中的值進行排序
uasort -- 使用用戶自定義的比較函數(shù)對數(shù)組中的值進行排序并保持索引關聯(lián)
uksort -- 使用用戶自定義的比較函數(shù)對數(shù)組中的鍵名進行排序
array_multisort -- 對多個數(shù)組或多維數(shù)組進行排序
例test.php
<?php
$arr = array("FILE12dddd.TXT", "file.txt", "a"=>"file2ddddddddddd.txt", "fi.txt", "file11.txt");
print_r($arr);
echo '<br>';
uasort($arr, function($a, $b){
$alen = strlen($a);
$blen = strlen($b);
if($alen > $blen){
return -1;
}else if($alen < $blen) {
return 1;
}else{
return 0;
}
});
print_r($arr);