新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
php文件怎么按修改時間排序
本文操作環(huán)境:Windows7系統(tǒng),php7.4版,Dell G3電腦。

博望網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,博望網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為博望上1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的博望做網(wǎng)站的公司定做!
php 文件怎么按修改時間排序?
php遍歷目錄下文件并按修改時間排序操作示例
php 遍歷目錄下文件方法:
//遍歷目錄下文件方法
function printdir($dir)
{
$files = array();
//opendir() 打開目錄句柄
if($handle = @opendir($dir)){
//readdir()從目錄句柄中(resource,之前由opendir()打開)讀取條目,
// 如果沒有則返回false
while(($file = readdir($handle)) !== false){//讀取條目
if( $file != ".." && $file != "."){//排除根目錄
if(is_dir($dir . "/" . $file)) {//如果file 是目錄,則遞歸
$files[$file] = printdir($dir . "/" . $file);
} else {
//獲取文件修改日期
$filetime = date('Y-m-d H:i:s', filemtime($dir . "/" . $file));
//文件修改時間作為健值
$files[$filetime] = $file;
}
}
}
@closedir($handle);
return $files;
}
}
對返回數(shù)組按時間排序
//根據(jù)修改時間對數(shù)組排序
function arraysort($aa) {
if( is_array($aa)){
ksort($aa);
foreach($aa as $key => $value) {
if (is_array($value)) {
$arr[$key] = arraysort($value);
} else {
$arr[$key] = $value;
}
}
return $arr;
} else {
return $aa;
}
}
$dir = "/php";
//輸出 /php 下所有文件
print_r(arraysort(printdir($dir))); 新聞標題:php文件怎么按修改時間排序
URL分享:http://m.fisionsoft.com.cn/article/cdoegcp.html


咨詢
建站咨詢
