Alreet All
我正在尝试组织一个foreach循环返回的文件列表 - 文件标有一个月:例如报告 - 2011年1月,报告 - 2011年2月等
他们目前以随机顺序吐出它们,例如7月,2月,12月,3月,我希望它们按顺序出现,如1月,2月,3月,4月等.
你们能否阐明我将如何做到这一点.
这是我的功能:
function getDirectoryList($directory) {
$results = array();
$handler = opendir($directory);
while ($file = readdir($handler)) {
if ($file != "." && $file != ".." && $file != "img") {
$results[] = $file;
}
}
closedir($handler);
return $results;
}
Run Code Online (Sandbox Code Playgroud)
这是对函数的调用:(注意"filepath"是使用define()设置的)
$files = getDirectoryList(filepath.$username."/".date("Y"));
Run Code Online (Sandbox Code Playgroud)
这是foreach循环:
foreach ($files as $f) {
$path_parts = pathinfo(filepath.$f);
$dir = $path_parts['dirname'];
$base = $path_parts['basename'];
$ext = $path_parts['extension'];
$fname = $path_parts['filename'];
echo "<div class='file ".$ext."'>".
"<a href='".downloadpath.$username."/".$f."' target='_blank' …Run Code Online (Sandbox Code Playgroud)