Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:12:41+00:00 2026-06-16T04:12:41+00:00

I am building a page navigation based on php files in a directory. At

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:12:43+00:00Added an answer on June 16, 2026 at 4:12 am

    You’ll need to push the index.php value to the top before iterating;

    $key = array_search('index.php', $files);
    unset($files[$key]);
    natsort($files);
    array_unshift($files, 'index.php');
    

    Then, in your iteration, just look for the value index.php and change it to [1]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a single-page application. At the moment, I also have several independent pages
Building a website using a PHP based Ecommerce product Magento. The problem I have
I'm new to PHP, and building a page that displays a customer order form
Scenario: building a site where navigation will be in master page in either left
I am building a Silverlight 3.0 app based on the Silverlight Navigation Application template.
I'm currently building a 6 page site and have finished the template for the
On this page: http://thegoodgirlsnyc.com/test/new/who.php I'm working on building a vertical slider. Several aspects are
I'm building a small-scale website (a personal one) in which each page would have
I'm building a simple website with few pages such as index.php, about.php etc. I've
Building an offline web app in VS2010. I have a master page with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.