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

本文章为各位介绍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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.