How do I display folders in date of creation order?

前端 未结 3 496
说谎
说谎 2021-01-22 12:41

I am new to PHP and developing a project called BaboonHut.com, I am coding it in PHP as the best way to learn is by just diving in. Anyway to the question, the snippet of code b

3条回答
  •  情话喂你
    2021-01-22 13:18

    You can't beat DirectoryIterator.

    $files = array();
    $dir = new DirectoryIterator('.');
    foreach ($dir as $fileinfo) {
       // Add only directories into a associative array, that key is it `MTime`
       if($fileinfo->isDir()){
           $files[$fileinfo->getMTime()] = $fileinfo->getFilename();
       }
    }
    
    // Then, key sort it.
    ksort($files);
    

提交回复
热议问题