0
,如果我有一个这样的数组(wihin一个循环 - 所以它充满了当然超过1项):数组排序
$returnArray[] = array("type" => $dirinfo[0],"fileSize" => $this->ByteSize($dirinfo[1]),"fileName" => $dirinfo[2]);
字段“类型“可以是”文件夹“或”文件“,但它们混合在一起, 所以像文件夹,文件,文件,文件夹,文件夹,文件等
我想排序文件夹上的第一和然后文件...(如Windows文件夹显示行为)
我玩过array_multisort,但只是不能让它工作...我该怎么做?
他们的例子是这个9though我想同样的返回数组刚刚整理,而不是一个新的数组:
foreach ($data as $key => $row) {
$volume[$key] = $row['volume'];
$edition[$key] = $row['edition'];
}
// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
所以我做了这个:
// tmp try sorting
foreach ($returnArray as $key => $row) {
$type[$key] = $row['type'];
$fileSize[$key] = $row['fileSize'];
$fileName[$key] = $row['fileName']
}
// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
array_multisort($type, SORT_DESC, $fileName, SORT_ASC, $fileSize, SORT_ASC, $rfileArray);
ooooh这就是...(我可以在文件名之后进行另一个排序,以便它的顺序为alphab。) – renevdkooi