title: PHP Navigation, is there a better way to do this?
body: <p>I am fairly new to using PHP, before this navigation the extent of my PHP use was simple includes.  </p>
  
  <p>I have written a navigation.php file that generates links for a navigation dynamically using variables pulled from an array inside variables.php  </p>
  
  <p><em><strong>The overall goal is to add/subtract links, subnavs, sub-subnavs, sub-sub-subnavs only by editing variables.php</em></strong></p>
  
  <p>The method I am using to generate the HTML structure feels clunky to me, it works just fine but I feel like there is a simpler way of doing this...  </p>
  
  <p>Also, I require additional styling for any LI that has a subnav present (an arrow to indicate a subnav is present).  I would like to generate that dynamically.  </p>
  
  <p>That said my questions are:</p>
  
  <ol>
  <li>Is there a simpler way of doing this?</li>
  <li>Is there a way to generate my 's dynamically based on whether there is a sub-nav present?</li>
  </ol>
  
  <p><em><strong>Each page has the following code, it changes depending on the page.</em></strong></p>
  
  <pre><code>&lt;?php $title = 'Home'; ?&gt;
  </code></pre>
  
  <p><em><strong>My variables.php :</em></strong></p>
  
  <pre><code>&lt;!-- NAVIGATION ARRAY --&gt;
  
  &lt;?php
  $nav_mini = array(
      'Home' =&gt; 'index.php',
      'About' =&gt; 'about.php',
      'Services' =&gt; 'services.php'
      );
  ?&gt;
  
  &lt;?php
  $nav_main = array(
      'Home' =&gt; 'index.php',
      'About' =&gt; 'about.php',
      'Services' =&gt; 'services.php',
      'Portfolio' =&gt; 'contact.php',
      'Clients' =&gt; 'about.php',
      'Gallery' =&gt; 'services.php',
      'News' =&gt; 'services.php',
      'Contact Us' =&gt; 'contact.php'
      );
  ?&gt;
  
  &lt;?php // SUB NAV ARRAYS
  
  $nav_sub_about = array(
      'Our Team' =&gt; 'about.php'
      );
  
  $nav_sub_michael = array(
      'Michael' =&gt; 'index.php',
      'Aaron' =&gt; 'about.php',
      'Kenny' =&gt; 'about.php',
      'David' =&gt; 'about.php'
      );
  
  $nav_sub_services = array(
      'Get Found' =&gt; 'about.php'
      );
  
  ?&gt;
  </code></pre>
  
  <p><em><strong>Navigation PHP File main-nav.php</em></strong></p>
  
  <pre><code>    &lt;?php 
  
          foreach ( $nav_main as $key =&gt; $value ) {
  
              echo "&lt;li&gt;&lt;a ";
                  echo "class='"; // STARTS CLASS=
                  if ( $title == $key) { 
                  echo "active "; }// ADDS ACTIVE CLASS TO LINK OF CURRENT PAGE
              echo "' "; // END QUOTES FOR CLASS="
  
  
              echo "href='$value'&gt;$key";
  
                  if ( $key == "About") { // STARTS IF SEQUENCE FOR SUBNAV ARROWS
                      echo "&lt;span class='arrow'&gt; +&lt;/span&gt;";}
                  elseif ( $key == "Services") {
                      echo "&lt;span class='arrow'&gt; +&lt;/span&gt;";}
  
              echo "&lt;/a&gt;\n";  // END ANCHOR TAG FOR MAIN NAV LINKS
  
  
  
  //----------------------------------------------------------------------------------------------------------//
  // PLEASE START SUB-NAVS HERE ------------------------------------------------------------------------------//
  // AT THIS POINT A NEW &lt;LI&gt; IS GENERATED FROM THE FIRST FOREACH, IF THE BELOW IS TRUE IT POPULATES A SUBNAV //      
  
  
          if ( $key == "About"){  // START SUBNAV FOR ABOUT
              echo "&lt;ul class='main-sub-nav'&gt;"; // THIS LINE WAS ADDED TO START THE &lt;UL&gt; FOR THE SUBNAV, IT ENDS ON LINE 14
  
              foreach ( $nav_sub_about as $key =&gt; $value ) {
                  echo "&lt;li&gt;&lt;a href='$value'&gt;$key";
  
                      if ( $key == "Our Team") { // STARTS IF SEQUENCE FOR SUBNAV ARROWS
                      echo "&lt;span class='arrow'&gt; +&lt;/span&gt;";}
  
                  echo "&lt;/a&gt;\n"; // ENDS ANCHOR TAG FROM SUBNAV LI
  
                      // SUB-SUB-NAV STARTS HERE
                          if ( $key == 'Our Team') {
                          echo "&lt;ul class='main-sub-sub-nav'&gt;"; // THIS STARTS THE UL FOR SUB-SUB-NAV
  
                              foreach ($nav_sub_michael as $key =&gt; $value ) {
                          echo "&lt;li&gt;&lt;a href='$value'&gt;$key&lt;/a&gt;&lt;/li&gt;\n";
                      }
                      echo "&lt;/ul&gt;"; // THIS ENDS THE SUB-SUB-NAV UL STARTED ON LINE 34
                  echo "&lt;/li&gt;";}// THIS IS THE END IF &lt;LI&gt; FROM THE SECOND FOREACH ON LINE 35
  
          }
  
          echo "&lt;/ul&gt;"; // THIS WAS ADDED TO END THE SUBNAV &lt;UL&gt; STARTED ON LINE 11
          echo "&lt;/li&gt;";} // THIS IS THE END OF THE &lt;LI&gt; FROM THE FIRST FOREACH ECHO FROM LINE 8
  
  //----------------------------------------------------------------------------------------------------------//
  // AT THIS POINT A NEW &lt;LI&gt; IS GENERATED FROM THE FIRST FOREACH, IF THE BELOW IS TRUE IT POPULATES A SUBNAV //
  
              if ( $key == "Services"){
                  echo "&lt;ul class='main-sub-nav'&gt;"; // THIS LINE WAS ADDED TO START THE &lt;UL&gt; FOR THE SUBNAV, IT ENDS ON LINE 14
  
                  foreach ( $nav_sub_services as $key =&gt; $value ) {
                      echo "&lt;li&gt;&lt;a href='$value'&gt;$key&lt;/a&gt;&lt;/li&gt;\n";}
                  echo "&lt;/ul&gt;"; // THIS WAS ADDED TO END THE SUBNAV &lt;UL&gt; STARTED ON LINE 11
                  echo "&lt;/li&gt;";} // THIS IS THE END OF THE &lt;LI&gt; FROM THE FIRST FOREACH ECHO FROM LINE 8
  
  
  
          } // THIS BRACKET ENDS THE ENTIRE SET OF PHP.  ITS PAIR IS ON LINE 19
  
  ?&gt;
  </code></pre>
  
  <p><em><strong>The overall goal is to add/subtract links, subnavs, sub-subnavs, sub-sub-subnavs only by editing variables.php</em></strong></p>
  
  <p>Here is a live example of this nav structure working...
  <a href="http://khill.mhostiuckproductions.com/siteLSSBoilerPlate/" rel="nofollow">http://khill.mhostiuckproductions.com/siteLSSBoilerPlate/</a></p>