I am using
foreach(glob("config/pages/*.php") as $page){
to get the list of all files in the directory of config/pages/
Can I have this show up by the oldest file first and the newest file last?
I am wanting to make a navigational menu out of all of this. My full source code is as follows but I need the oldest file to show up first, Maybe I could add a variable to each file like: `$order = 1;' where the number would be the order in the list?
so for example for page home.php
the $order
would be equal to 0 and about.php
would be equal to 1. And then somehow sorting based on counting in order from 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>";
}
?>