我有一个名为$gatherArr
的简单PHP数组,如下所示:
$gatherArr = [
["catCode"=>"ac", "catName"=>"Armchair"],
["catCode"=>"sf", "catName"=>"Sofa"],
["catCode"=>"st", "catName"=>"Side Table"],
["catCode"=>"ct", "catName"=>"Coffee Table"],
["catCode"=>"dt", "catName"=>"Table"],
["catCode"=>"cs", "catName"=>"Chair / Stool"],
["catCode"=>"sb", "catName"=>"Side Board"],
];
我想用PHP代码构建一个菜单栏,并从$gatherArr
获取下拉列表。这是我的HTML代码。
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="index.php">About</a></li>
<li><a href="news.php">News</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Collection <b class="caret"></b></a>
<ul class="dropdown-menu">
<?php
include './productData.php';
foreach ($gatherArr as $name => $detail) {
echo" {$detail}<br />";
}
?>
</ul>
</li>
<li><a href="ordering.php">Ordering</a></li>
<li><a href="contactus.php">Contact</a></li>
</ul>
</div>
我在下拉菜单栏中显示错误。我也尝试更改echo" {$detail}<br />"; To $name
,但我在菜单栏中输入了0到6的数字
谢谢!
答案 0 :(得分:0)
{$细节}
是数组,您无法打印或回显数组。但是,您可以打印它的特定元素,如:
{$细节[&#39; catCode&#39;]}
或
{$细节[&#39; catName&#39;]}