title: Dropdown menu with foreach php
body: <p>I show my dropdown menu with 2 level as the following:</p>
  
  <pre><code>&lt;nav id= "main-menu"&gt;
  
      &lt;?php foreach($data['mainMenu'] as $row) // $data['mainMenu'] is a table MainMenu in database.
      {
  
      if($row['parent']&lt;=0){
              ?&gt;
      &lt;dl class ="menudropdown"&gt;
  
          &lt;!-- show parent menu--&gt;
  
          &lt;dt id="&lt;?php echo $row['shortName'].'-ddheader'; ?&gt;" onmouseover="ddMenu('&lt;?php echo $row['shortName'];?&gt;',1)" onmouseout="ddMenu('&lt;?php echo $row['shortName'];?&gt;',-1)"&gt;&lt;?php echo $row['fullName'];?&gt; &lt;/dt&gt;   
          &lt;!--/parent menu--&gt;
  
           &lt;!--show childmenu--&gt;
          &lt;dd id="&lt;?php echo $row['shortName'].'-ddcontent';?&gt;" onmouseover="cancelHide('&lt;?php echo $row['shortName'];?&gt;')" onmouseout="ddMenu('&lt;?php echo $row['shortName'];?&gt;',-1)"&gt;
              &lt;ul&gt;
                  &lt;?php foreach($data['mainMenu'] as $row1)
                  {
  
                  if($row1['parent']==$row['id']){
                  ?&gt;
                  &lt;li&gt;&lt;a href ="#" class ="underline"&gt; &lt;?php echo $row1['fullName'];?&gt;&lt;/a&gt;&lt;/li&gt;
                  &lt;?php 
                  }
                  }
                  ?&gt;
              &lt;/ul&gt;
          &lt;/dd&gt;
          &lt;!--show childmenu--&gt;
      &lt;/dl&gt;
      &lt;?php 
      }
      }?&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>A result is only the first <code>row['fullName']</code>in <code>$data['mainMenu']</code> Which is shown. It shows only one <code>dl</code> element. The first foreach doesn't continue.</p>
  
  <p>[UPDATE]</p>
  
  <p>If I convert <code>$data['mainMenu']</code> to <code>$tblMainMenu</code> array:</p>
  
  <pre><code>$tblMainMenu=[];
  $index = 0;
  foreach( $data['mainMenu'] as $tbl)
      {
          $tblMainMenu[$index] = array(
                                      'id' =&gt; $tbl['id'],
                                      'fullName' =&gt; $tbl['fullName'],
                                      'shortName' =&gt; $tbl['shortName'],
                                      'parent' =&gt; $tbl['parent'],
                                      'active' =&gt; $tbl['active'],
                                  );
          $index++;
      }
  </code></pre>
  
  <p>And try to loop with <code>$tblMainMenu</code>, It works perfectly. </p>
  
  <p>What is problem with 2 foreach? How php execute the code?
  I cannot see what is problem with this code above.</p>