PHP数组和导航栏下拉列表

时间:2016-12-25 07:46:02

标签: php html

我有一个名为$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的数字

谢谢!

1 个答案:

答案 0 :(得分:0)

  

{$细节}

是数组,您无法打印或回显数组。但是,您可以打印它的特定元素,如:

  

{$细节[&#39; catCode&#39;]}

  

{$细节[&#39; catName&#39;]}