title: Get value of array and display it into dropdown as parent and child
body: <p>I am working in codeigniter. I want to display category dropdowna as parent category and its subcategory in sequance. Here I have an array like this:</p>
  
  <pre><code>Array
  (
  [category] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 1
                  [Name] =&gt; web
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 2
                  [Name] =&gt; Travels
                  [child_cat] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [id] =&gt; 3
                                  [Name] =&gt; Food
                              )
  
                      )
  
              )
       )
  )
  </code></pre>
  
  <p>Here I want to display <strong>Travels</strong> as <strong>parent category</strong> in dropdown box and display <strong>Food</strong> under the <strong>Travels</strong> category.</p>
  
  <p>I have created select box like this :</p>
  
  <pre><code>&lt;select class="form-control" id="sel1"&gt;
      &lt;option value="0"&gt;Select&lt;/option&gt;
          &lt;?php
              foreach($category as $cat)
              {
                   if($cat['child_cat'] == "")
                   {  
          ?&gt;
      &lt;option value="&lt;?php echo $cat['id']; ?&gt;"&gt;&lt;?php echo $cat['Name']; ?&gt;&lt;/option&gt;
          &lt;?php
              }
                   else
                   {
                      foreach($cat['child_cat'] as $ch)
                      {
          ?&gt;
                          &lt;option value="&lt;?php echo $ch['id']; ?&gt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;?php echo $ch['Name']; ?&gt;&lt;/option&gt;
          &lt;?php
                      }
                  }
             }
          ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Here it can not show <strong>Travels</strong> as parent category. <strong>Food</strong> is show under the web instead of Travels. So what code should I have to write?</p>