使用数组进行导航[复制]

This question already has an answer here:

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>
</div>

$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

Change this:

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

To this:

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

And you should be good to go.

Check up on strings, particular interpolation http://php.net/manual/en/language.types.string.php