title: dynamic menu boostrap with php
body: <p>My responsive dynamic menu under boostrap 4 doesn't work.</p>
  
  <p>I am blocked at level 2. The submenu with the dropdown doesn't work</p>
  
  <p>My code: <a href="http://www.bootply.com/vtv1oTt9mS" rel="nofollow noreferrer">http://www.bootply.com/vtv1oTt9mS</a></p>
  
  <pre><code>&lt;div class="headerLine"&gt;&lt;/div&gt;
  &lt;div class="backgroundSuperfish"&gt;
  
    &lt;nav class="navbar navbar-light bg-faded"&gt;
      &lt;button class="navbar-toggler hidden-lg-up" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"&gt;&lt;/button&gt;
      &lt;div class="collapse navbar-toggleable-md" id="navbarResponsive"&gt;
          &lt;ul class="nav navbar-nav"&gt;
  &lt;?php
   // level 1
              foreach($menu_parent as $key =&gt; $menus) {
                if ($menus['link'] != '') {
                  echo '&lt;li class="nav-item"&gt;&lt;a class="nav-link" href="'. OSCOM::link($menus['link']) . '"&gt;' . $menus['label'] . '&lt;/a&gt;&lt;/li&gt;';
                } else {
                  echo '&lt;li class="nav-item dropdown"&gt;&lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;' . $menus['label'] . '&lt;/a&gt;';
                }
  
  // level 2
                if (!is_null($menus['sub_menu'])) {
                  echo '&lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;';
  
                  foreach($menus['sub_menu'] as $second_level) {
                    if ($menu_sub[$second_level]['link'] != '')  {
                      echo '&lt;a class="dropdown-item" href="'. OSCOM::link($menu_sub[$second_level]['link']) . '"&gt;' . $menu_sub[$second_level]['label'] . '&lt;/a&gt;';
                    } else {
                      echo '&lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;' . $menu_sub[$second_level]['label'] . '&lt;/a&gt;';
                    }
                  }
  // level 3
                  if ($menu_sub[$second_level]['sub_menu'] != '')  {
                    echo '&lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;';
  
                    foreach($menu_sub[$second_level]['sub_menu'] as $third_level) {
                      if (!is_null($menu_sub[$third_level]['link'])) {
                        echo '&lt;a class="dropdown-item" href="'. OSCOM::link($menu_sub[$second_level]['link']) . '"&gt;' . $menu_sub[$third_level]['label'] . '&lt;/a&gt;';
                      } else {
                        echo '&lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;' . $menu_sub[$third_level]['label'] . '&lt;/a&gt;';
                      }
                    }
  
  
  // level 4
                    if ($menu_sub[ $third_level ]['sub_menu'] != '')  {
                      echo '&lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;';
  
                      foreach($menu_sub[ $third_level ]['sub_menu'] as $fourth_level) {
                        if (!is_null($menu_sub[$fourth_level]['link'])) {
                          echo '&lt;a class="dropdown-item" href="'. OSCOM::link($menu_sub[$second_level]['link']) . '"&gt;' . $menu_sub[$fourth_level]['label'] . '&lt;/a&gt;';
                        } else {
                          echo '&lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;' . $menu_sub[$fourth_level]['label'] . '&lt;/a&gt;';
                        }
                      }
                      echo '&lt;/div&gt;';
                    } // end level 4
  
                    echo '&lt;/div&gt;';
                  } // end level 3
                  echo '&lt;/div&gt;';
                } // end level 2
                echo '&lt;/li&gt;';
              }
            ?&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/nav&gt;
  &lt;/div&gt;
  &lt;div class="clearfix"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Generate HTML:</p>
  
  <pre><code>        &lt;div class=""&gt;
              &lt;nav class="navbar navbar-light bg-faded"&gt;
                  &lt;button class="navbar-toggler hidden-lg-up" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"&gt;&lt;/button&gt;
                  &lt;div class="collapse navbar-toggleable-md" id="navbarResponsive"&gt;
                      &lt;ul class="nav navbar-nav"&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Home&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="dropdown-item" href="index.php"&gt;Back Office&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="../index.php"&gt;Store&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Configuration&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;My store&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;My backoffice&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Customers B2C&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Customers B2B&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Modules&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;SEO / Social networking&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Location &amp;amp; taxes&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Others&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Sessions &amp;amp; cache&lt;/a&gt;
                                  &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                      &lt;a class="dropdown-item" href=""&gt;Cache Control&lt;/a&gt;
                                      &lt;a class="dropdown-item" href=""&gt;gzip compression&lt;/a&gt;
                                      &lt;a class="dropdown-item" href=""&gt;Logging&lt;/a&gt;
                                      &lt;a class="dropdown-item" href=""&gt;Sessions&lt;/a&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Catalog&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="dropdown-item" href="categories.php"&gt;Categories&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="products.php"&gt;Products&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="quick_updates.php"&gt;Quick update&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="products_attributes.php"&gt;Product attributs&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="products_extra_fields.php"&gt;Products extra fields&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="manufacturers.php"&gt;Brands&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="suppliers.php"&gt;Suppliers&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="products_archive.php"&gt;Products archive&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Customers&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="dropdown-item" href="orders.php"&gt;Orders&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="customers.php"&gt;Customers&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="members.php"&gt;B2B customers pending&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="customers_groups.php"&gt;Customers group&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="reviews.php"&gt;Reviews&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="customers_feedback.php"&gt;Customers feedback&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="mail.php"&gt;Customer contact&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="contact_customers.php"&gt;Customers contact support&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Marketing&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="dropdown-item" href="specials.php"&gt;Specials&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="discount_coupons.php"&gt;Discount coupons&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="products_favorites.php"&gt;Favorites&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="products_featured.php"&gt;Featured product&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="products_related.php"&gt;Cross sell &amp;amp; related products&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="banner_manager.php"&gt;Banner management&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Communication&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="dropdown-item" href="newsletters.php"&gt;Newsletter&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="page_manager.php"&gt;Pages management&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="blog_categories.php"&gt;Blog categories&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="blog_content.php"&gt;Blog content&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Reports&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Products Statistics&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Financial statistics&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Products management&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="stats_suppliers.php"&gt;Orders suppliers&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="stats_pool_customers.php"&gt;Pool customers&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="stats_newsletter_no_account.php"&gt;Anonymous subscription&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="stats_email_validation.php"&gt;Email analysis&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Design&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Design Configuration&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Products listing&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Store index &amp;amp; categories&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Customers Account&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Order process&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="modules.php?set=modules_products_info"&gt;Products description&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Communication&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Miscellaneous&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Layout&lt;/a&gt;
                                  &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                      &lt;a class="dropdown-item" href=""&gt;Left &amp;amp; right boxes&lt;/a&gt;
                                      &lt;a class="dropdown-item" href=""&gt;Site header&lt;/a&gt;
                                      &lt;a class="dropdown-item" href=""&gt;Site footer&lt;/a&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item dropdown"&gt;
                              &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Tools&lt;/a&gt;
                              &lt;div class="dropdown-menu" aria-labelledby="responsiveNavbarDropdown"&gt;
                                  &lt;a class="dropdown-item" href="backup.php"&gt;Database backup&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Upgrade / Add ons&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;HTML editor&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Datas export&lt;/a&gt;
                                  &lt;a class="nav-link dropdown-toggle" href="#" id="responsiveNavbarDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"&gt;Security informations&lt;/a&gt;
                                  &lt;a class="dropdown-item" href="whos_online.php"&gt;Who's Online&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
                  &lt;/div&gt;
              &lt;/nav&gt;
  </code></pre>