如何使用php词典进行foreach循环?

10 php foreach dictionary

我试图制作一个PHP导航栏的东西.我有html代码,我想要做的是使用php字典("Home"=>"http://www.domain.com/")并将其转换为html代码.

And*_*ndy 13

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


Raf*_*ler 7

foreach($arr as $key=>$value) {
    // your code here
}
Run Code Online (Sandbox Code Playgroud)

我不知道你想如何制作导航栏,但是如果你对HTML有任何了解,你应该可以从这里开始.