0

I know this is going to be voted as a bad question but I always have trouble with these. I am making a php navigation using arrays and my code keeps falling short, mainly in foreach statements. Hopefully if you look you can see where I am trying to go

<html>
    <head>
        <title>navigation</title>
        <?php
            $pages = array("index.html" => "Home");
        ?>
    </head>
    <body>
        <ul>
            <?php
                foreach($pages as $link => $page){
                    echo '<li> <a href=" $link "> $page </a> </li>';
                }
            ?>
        </ul>
    </body>
</html>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Dré Ellis
  • 33
  • 1
  • 8

2 Answers2

0

$link and $page aren't going to get parsed here, since they're within single quotes:

echo '<li> <a href=" $link "> $page </a> </li>';

Do this instead:

echo '<li> <a href="' .$link . '"> ' . $page . '</a> </li>';

http://php.net/manual/en/language.types.string.php

mopo922
  • 6,293
  • 3
  • 28
  • 31
  • 1
    Yep, that works too. I prefer "my" way just so I can always have double-quotes in my HTML. – mopo922 Dec 22 '14 at 21:53
  • Thank you, I always forget that part – Dré Ellis Dec 22 '14 at 21:54