按创建日期排序php

时间:2019-01-14 03:42:53

标签: php wordpress sorting date

我有一个音频播放器,它从一个文件夹中提取音频,该文件夹当前正在按名称排序,但是我想按创建日期对其进行排序。任何帮助将不胜感激。

$media = array();

    $di = new DirectoryIterator($dir);
    foreach ($di as $fileinfo) {
        $path_info = pathinfo($fileinfo->getPathname());
        if(isset($path_info['extension'])){
            if(in_array(strtolower($path_info['extension']), $allowed_files)){
                $fn = $fileinfo->getPathname();
                $media[] = array( 
                    "SITE_URL" => SITE_URL, 
                    "SITEPATH" => SITEPATH, 
                    "fullpath" => SITE_URL.'/'.path2url(realpath($path_info['dirname'])).'/'.$path_info['basename'],  
                    "basename" => $path_info['basename'], 
                    "extension" => $path_info['extension'],
                    "dirname" => realpath($path_info['dirname']),
                    "filename" => $path_info['filename']
                ); 
            }
        }

1 个答案:

答案 0 :(得分:2)

DirectoryIterator仅授予对access Timemodification timeinode change time的访问权限。如果自创建以来文件没有更改,DOM将相同,然后您可以将时间保存在modification time数组中,然后使用array_multisort对数组进行排序:

$media