Home >php教程 >PHP源码 >php按文件生成时间排序列出目录下的所有文件

php按文件生成时间排序列出目录下的所有文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:21:021472browse

本文章为各位介绍php按文件生成时间排序列出目录下的所有文件的例子,有兴趣的朋友不防进入参考。

<script>ec(2);</script>

先看文件列表:

php按文件生成时间排序列出目录下的所有文件

再看代码:
 代码如下 复制代码
$dir=’ass’;
$dp = dir($dir);
while ($file = $dp ->read()){
$filename=$dir.’/’.$file;
if($file!=’.'&&$file!=’..’){
$key=filectime($filename)*1000+rand(100,999);
$files[strval($key)]=$filename;
}
}
echo ‘
’;<br>
print_r($files);<br>
ksort($files);<br>
print_r($files);<br>
$keys = range(1,count($files));<br>
$arr=array_combine($keys,$files);<br>
print_r($arr);<br>
echo ‘
’;

打印结果:

php按文件生成时间排序列出目录下的所有文件

 代码如下 复制代码
Array
(
    [1] => 第十五课.ass
    [2] => 第二十一课.ass
    [3] => 第二十课.ass
    [4] => 第九课.ass
    [5] => 第二十六课.ass
    [6] => 第四课.ass
    [7] => 第十七课.ass
    [8] => 第二十二课.ass
    [9] => 第七课.ass
    [10] => 第三课.ass
    [11] => 第十八课.ass
)
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn