I am building a page navigation based on php files in a directory.
At the moment I have 5 files in my directory: index.php, 2.php, 3.php, 4.php, 5.php
With my limited PHP skills I have managed to work the code to display the navigation as: [2] [3] [4] [5] [index]
However I have hit a road block that is a little beyond me at this time.
I would like to have [index] displayed as [1], and I would like [1] to be displayed first.
I would like to have it look like this: [1] [2] [3] [4] [5]
<?php
$pathfiles = "../directory/";
$files = glob("../directory/*.php");
foreach( $files as $file ) {
echo '[<a href="'.($pathfiles).''
.basename($file).'">'
.basename($file, ".php").'</a>] ';
}
?>
Any help or leads would be appreciated. Thank you in advance for your time.
You’ll need to push the index.php value to the top before iterating;
Then, in your iteration, just look for the value index.php and change it to [1]