2016-12-25 59 views
0

我有一個簡單的PHP陣列稱爲$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

{$詳細}

是數組,則不能打印或回波陣列。你可以,但是,打印它的一個特定的元素,如:

{$細節[ 'catCode']}

{$細節[ 'catName']}

+0

感謝它的工作! – xhinvis