title: How to loop through array with indeterminate amount of children arrays
body: <p>Im trying to list categories with sub categories in my app - I can use either PHP or Javascript / Jquery for the following:</p>
  
  <p>I have an array of categories with sub categories appended as additional arrays</p>
  
  <p>the trick is that it can go as deep as there are sub categories.
  and sub categories can also have sub categories.</p>
  
  <p>Therefore for each category it can have as many children each of whom can have many children arrays.</p>
  
  <p>What would be the best way to loop through them to create a dropdown list?</p>
  
  <p>Here is the structure when dumping the main array:</p>
  
  <pre><code>array (size=2)
    0 =&gt; 
      array (size=4)
        'id' =&gt; int 1
        'name' =&gt; string 'Stationery' (length=10)
        'parent_id' =&gt; int 0
        'childs' =&gt; 
          array (size=1)
            0 =&gt; 
              array (size=4)
                ...
    1 =&gt; 
      array (size=3)
        'id' =&gt; int 4
        'name' =&gt; string 'boots' (length=5)
        'parent_id' =&gt; int 0
  </code></pre>
  
  <p>notice sub zero has a "childs" array
  when dumping this array i get:</p>
  
  <pre><code>array (size=1)
    0 =&gt; 
      array (size=4)
        'id' =&gt; int 2
        'name' =&gt; string 'pens' (length=4)
        'parent_id' =&gt; int 1
        'childs' =&gt; 
          array (size=1)
            0 =&gt; 
              array (size=4)
                ...
  </code></pre>
  
  <p>Notice this too has a child attached which when dumped looks like:</p>
  
  <pre><code>array (size=1)
    0 =&gt; 
      array (size=4)
        'id' =&gt; int 3
        'name' =&gt; string 'penfillers' (length=10)
        'parent_id' =&gt; int 2
        'childs' =&gt; 
          array (size=1)
            0 =&gt; 
              array (size=3)
                ...
  </code></pre>
  
  <p>Sneaky - this one also has another child!</p>
  
  <p>This can go as deep as there are sub categories</p>
  
  <p>How would i loop through them and have the output in a dropdown list?
  Im stumped as to how to loop infinitely until the chain ends.</p>
  
  <p>Thanks
  Jason</p>