我在用
foreach(glob("config/pages/*.php") as $page){
获取目录中所有文件的列表config/pages/
我可以先显示最旧的文件,最后显示最新的文件吗?
我想用所有这些制作一个导航菜单。我的完整源代码如下,但我需要首先显示最旧的文件,也许我可以向每个文件添加一个变量,例如:“$order = 1;”其中数字将是列表中的顺序?
例如对于页面home.php
the $order
将等于 0 并且about.php
等于 1。然后以某种方式基于从 0 开始计数的顺序进行排序?
<ul class="sidebar-nav">
<li class="sidebar-brand"><a href="#"><?php echo $config['site_title']; ?></a></li>
<?php
$files = glob("config/pages/*.php");
$files = array_combine(array_map("filemtime", $files), $files);
ksort($files);
foreach($files as $page){
// Remove the conifg/pages/ from the string
$strip1 = str_replace('config/pages/', '', $page);
// Remove the .php from the string
$strip2 = str_replace('.php', '', $strip1);
// Uppercase the first letter in the string
$capit = ucfirst($strip2);
// Re-define the string as the display title
$title = $capit;
// Remove the .php and replace it with .html
$html = str_replace('.php', '.html', $strip1);
// Re-define the string for the link url
$link = $html;
// Display the end string with html elements to user
echo "<li><a href='".$link."'>".$title."</a></li>";
}
?>
试试这个代码。我在我的项目中使用过,请检查。
$myarray = glob("config/pages/*.php");
usort($myarray, function($a,$b){
return filemtime($a) - filemtime($b);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)