php readdir 排序問題,如何依照日期進行排序
高洛峰
高洛峰 2017-05-16 13:04:28
0
1
747

目前是這麼寫的:

function posts_get($directory,$ext)
{
    if (is_dir($directory)) {
    $handle = opendir($directory);
    while ($file = readdir($handle)){
    $subdir = $directory . '/' .$file;
    if ($file != '.' && $file !='..' && is_dir($subdir)){
    posts_get($subdir,$ext);
    } else if( $file != '.' && $file != '..') {
    $fileInfo = pathinfo($subdir);
    $fileExt = $fileInfo['extension'];
    if ($fileExt == $ext){
    echo '文件名:' . $file . '————' . '路径:' . '//' .$_SERVER['HTTP_HOST'] . '/' .$directory . '/' . $file . '<br />';
    }}}
    closedir($handle); 
    }
}

取得posts目錄裡面的html文件,測試目錄裡面有5個文件,404.html,405.html,406.html,407.html,408.html

輸出的結果內容如下:

文件名:405.html————路径://hotbox.ryongyon.com/posts/405.html
文件名:406.html————路径://hotbox.ryongyon.com/posts/406.html
文件名:407.html————路径://hotbox.ryongyon.com/posts/407.html
文件名:408.html————路径://hotbox.ryongyon.com/posts/408.html
文件名:404.html————路径://hotbox.ryongyon.com/posts/404.html

請問如何將readdir的結果依照檔案所建立的日期進行排序

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回覆(1)
仅有的幸福
  • filectime取得檔案建立時間並轉換為時間戳

  • 定義一個空數組,並儲存數據,格式 时间戳=>文件名

  • ksort或者krsort對數組排序

  • done

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!