PHP read the folder directory, sorted by time, size sorting, sorting name

<?php
$dir = "./";//目录
 
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        $i = 0;
        while (($file = readdir($dh)) !== false) {
            if ($file != "." && $file != "..") {
                $files[$i]["name"] = $file;//获取文件名称
                $files[$i]["size"] = Round ((filesize ($ File) / 1024 ), 2 ); // Get File Size 
                $ Files [$ I] [ " Time " ] = DATE ( " Ymd H: I: S " , The filemtime ($ File) ); // Get file date of last modification 
                $ I ++ ; 
            } 
        } 
    } 
    closedir ($ DH); 
    the foreach ($ files AS $ K => $ V) { 
        $ size [$ K] = $ V [ ' size ' ]; 
        $ Time [$ K] = V $ [ ' Time ' ]; 
        $ name [$ K]V $ = [ ' name ' ]; 
    } 
    array_multisort ($ Time, SORT_DESC, SORT_STRING, $ Files); // sort by time
     // array_multisort ($ name, SORT_DESC, SORT_STRING, $ Files); // Sort by Name
     @ array_multisort ($ size, SORT_DESC, SORT_NUMERIC, $ Files); // Sort by size 
    print_r ($ Files); 
}
 ?>

principle:

? < PHP 
$ AR1 = Array ( 10 , 100 , 100 , 0 ); 
$ AR2 of = Array ( . 1 , . 3 , 2 , . 4 ); 
array_multisort ($ AR1, $ AR2 of); 

var_dump ($ AR1); 
var_dump ($ AR2 of );
 >? 

result: this example, after sorting, the first array will contain 0 , 10 , 100 , 100 . The second array may comprise 4 , 1 , 2 , 3 . After the second array corresponding to the item in the first array is also sorted ( 100 and 100 ). 

array (4) {
  [0]=> int(0)
  [1]=> int(10)
  [2]=> int(100)
  [3]=> int(100)
}
array(4) {
  [0]=> int(4)
  [1]=> int(1)
  [2]=> int(2)
  [3]=> int(3)
}

 

 

From: https://www.cnblogs.com/coolid/p/3651350.html

Guess you like

Origin www.cnblogs.com/init-007/p/11360064.html