Echo array elements

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello, I am new to coding in PHP, and had a question about a simple

I am trying to echo out the elements of an array for a sidenav in one
of my HTML pages, and I can't seem to figure out the syntax for
appending the element of the array into the path to the file. Here is
the code I have:

 include 'c:\inetpub\webroot\sheel\template\navbar.html';

 $fullPath = explode('/', $_SERVER['PHP_SELF']);
 echo "The foldername $fullPath[0]";
 echo "The filename $fullPath[1]";
 echo 'c:\inetpub\webroot\sheel\template\'.$($fullPath[1]).".html";

 $filename = 'c:\inetpub\webroot\sheel\template\' .
 $filename2 = 'c:\inetpub\webroot\sheel\template\' .

 if (file_exists($fileName)) {
    echo "c:\inetpub\webroot\sheel\template$fullPath[1].html";
    include 'c:\inetpub\webroot\sheel\template\'.
 else if (file_exists($fileName2)) {
    echo "c:\inetpub\webroot\sheel\template$fullPath[2].html";
    include 'c:\inetpub\webroot\sheel\template\'.
   echo "<ul id=\"secondaryNav\" ></ul>";}

Thanks for your help!

Re: Echo array elements wrote:
Quoted text here. Click to load it

I have not followed your code, but I noticed one thing that I do
differently.  I would always write this line:

     echo "c:\inetpub\webroot\sheel\template$fullPath[1].html";


     echo "c:/inetpub/webroot/sheel/template/" . $fullPath[1] . ".html";

     echo 'c:/inetpub/webroot/sheel/template/' . $fullPath[1] . '.html';

That is, I would separate the string from the variable explicitly and I
would use unix notation.  Otherwise (I'm not 100% certain), you may well

  echo "c:\inetpub\webroot\sheel\template\" . $fullPath[1] . ".html";

since the backslash is a quoting character.


Site Timeline