php readdir 排序问题,如何按照日期进行排序
高洛峰
高洛峰 2017-05-16 13:04:28
0
1
720

目前是这么写的:

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 학습자의 빠른 성장을 도와주세요!