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 8152939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:51:25+00:00 2026-06-06T15:51:25+00:00

Before I start, I should let you know that I’m hardly experienced in PHP.

  • 0

Before I start, I should let you know that I’m hardly experienced in PHP. In fact, I pretty much only started using it last week, so I’m using it as if it were JavaScript or something.

Anyway, I’m trying to streamline the dynamic serving of content, via PHP, on my website as much as best as I can and as I know how.

So, I do this by:

  1. Creating an array of every URL variable that I’m currently using.
  2. Querying IDPage(), which includes a FOR loop that cycles through the array, compares the index place to the current URL variable and returns the index place, if matched.
  3. Using the returned string to decide which content to include.

 

Pre-<!DOCTYPE>

<?php
    $root = $_SERVER["DOCUMENT_ROOT"];
    $array_IDs = array("404", "home", "item2", "item3", "item4");
    global $root, $array_IDs;
?>

<head>

<?php
    function IDPage(){
        for ($i = 0; $i < count($array_IDs); $i++){
            if (isset($_GET[$array_IDs[$i]])){
                return $array_IDs[$i];
            }
        }
    }
?>

<body>

<article>
    <?php 
        $response = IDPage();

        if ($response == "404"){
            include($root . "/path/file.ext");
        }

        if ($response == "home"){
            include($root . "/path/file.ext");
        }

        if ($response == "item2"){
            include($root . "/path/file.ext");
        }

        if ($response == "item3"){
            include($root . "/path/file.ext");
        }

        if ($response == "item4"){
            include($root . "/path/file.ext");
        }
    ?>
</article>

Using the current set up, the array always returns 0 and, with a little more digging, this seems to be because count() thinks that $array_IDs has no values. Yet, this works if you place the FOR loop in the same block as <body>s (and mod the code to work from the same block, of course).

Again, I know it’s crude but it’s only a small site, I don’t know any better and I don’t think I’m ready to get into databases and all that yet. If anyone’s got any better ideas, though, feel free to let me know, so long as I’m capable. :L

  • 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-06T15:51:27+00:00Added an answer on June 6, 2026 at 3:51 pm

    Use global keyword inside your function to import that variable in your function:

    function IDPage(){
        global $array_IDs;
        for ($i = 0; $i < count($array_IDs); $i++){
            if (isset($_GET[$array_IDs[$i]])){
                return $array_IDs[$i];
            }
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before start let me tell my experience: I am experienced with C#.NET, web services,
I usually try to do TDD with not much analysis (no diagrams) before start
Before you start flaming, I'm going to tell you that I am trying to
Before you start laughing at such a simple question let me explain: I am
I want to get one record before start date and end date DtpFrom means
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
I am working on a Media up-loader which uploads images to Server. Before start
Before I start: I'm programming for Iphone, using objective C. I have already implemented
Before you start marking this as a duplicate , read me out. The other
Before I start this may be hard for some people to understand. Sorry. I

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.