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

目前是这么写的:

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学习者快速成长!