How can I do a foreach loop using php dictionaries? How can I do a foreach loop using php dictionaries? php php

How can I do a foreach loop using php dictionaries?


<ul><?php foreach ($links as $title => $url): ?>    <li><a href="<?php echo htmlentities($url); ?>"><?php echo htmlentities($title); ?></a></li><?php endforeach; ?></ul>


foreach($arr as $key=>$value) {    // your code here}

I have no idea how you want to make your navbar, but with any knowledge of HTML you should be able to go from here.


Fastest

<?phpforeach($array as $name => $link){    echo '<a href="',$link,'">',$name,'</a>\n';}?>

Easier to read and understand but slower

<?phpforeach($array as $name => $link){    echo "<a href='$link'>$name</a>\n";}?>