回显php目录中最近的文件夹?
我尝试过这段代码,但它显示给定目录中的所有文件夹回显php目录中最近的文件夹?,php,html,Php,Html,我尝试过这段代码,但它显示给定目录中的所有文件夹 <?php $dir = './folder';$ffs = scandir($dir); foreach($ffs as $ff){ if($ff != '.' && $ff != '..'){ if(strpos($ff, '.')) {} else { $ff = ucfirst($ff); echo "<a href='../subjects/" . strtolower($ff) . "'>".$ff.
<?php $dir = './folder';$ffs = scandir($dir); foreach($ffs as $ff){ if($ff != '.' && $ff != '..'){ if(strpos($ff, '.')) {} else { $ff = ucfirst($ff); echo "<a href='../subjects/" . strtolower($ff) . "'>".$ff.'</a><br>'; } } } echo '</ol>'; }?>
只需使用文件列表的最后一个条目。你不需要重复它
<?php
$dir = './folder';
$ffs = scandir($dir);
if (is_array($ffs)) {
$name_of_last_file = $ffs[count($ffs) - 1];
if ($name_of_last_file != ".." && $name_of_last_file != "..") {
echo "<a href='../subjects/" . strtolower($name_of_last_file) . "'>". $name_of_last_file .'</a><br>';
}
}
echo '</ol>';
}?>