php对文件排序,如何对php列出的文件进行排序

答案是将条目添加到数组中并对其进行排序

但说真的。你的代码(我不知道你从哪里剪的)看起来真的很过时。有更优雅的方法可以做到这一点。

只需修改代码,使其基本上满足您的要求,而无需mroe,您可以拥有以下内容:

// Start directory

getDirectory('../gallery/photos');

function getDirectory( $path = '.', $level = 0 ){

// Directories to ignore when listing output.

$ignore = array( '.', '..' );

// Open the directory to the handle $dh

//$dh = @opendir( $path );

// Loop through the directory

//while( false !== ( $file = readdir( $dh ) ) ) {

$files = $files = glob($path.DS."*");

sort($files);

foreach($files as file) {

// Change filename to display date

$displaydate= date('jS M Y', strtotime($file));

// Check that this file is not to be ignored

if( !in_array( $file, $ignore ) ) {

// Indent spacing for better view

$spaces = str_repeat( ' ', ( $level * 5 ) );

// Show directories only

if(is_dir( "$path/$file" ) ){

// Re-call this same function but on a new directory.

// this is what makes function recursive.

echo "$spaces$displaydate
";

getDirectory( "$path/$file", ($level+1) );

}

}

}

// Close the directory handle

closedir( $dh );

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值