title: looping array value with function php
body: <p>I'm trying to create multi level dropdown menu with mysql as store data, and i use twig as theme engine, i know there is ton of code outside but, all of them HTML as the output, since i use twig, so i need array as the output, and let twig render it,(or maybe there is other option, let me know if so).<br>
  this code work if i use html as output. but if  i change to array as output the problem is 2nd menu level only show 1 array or first array, it not loop.<br>
  this is my array output from mysql query , </p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [id] =&gt; 1
              [title] =&gt; Dashboard
              [link] =&gt; 1.html
              [parent_id] =&gt; 0
          )
  
      [1] =&gt; Array
          (
              [id] =&gt; 2
              [title] =&gt; Master Data
              [link] =&gt; 2.html
              [parent_id] =&gt; 0
          )
  
      [2] =&gt; Array
          (
              [id] =&gt; 3
              [title] =&gt; submaster
              [link] =&gt; 11.html
              [parent_id] =&gt; 2
          )
      [3] =&gt; Array
          (
              [id] =&gt; 4
              [title] =&gt; submaster
              [link] =&gt; 12.html
              [parent_id] =&gt; 2
          )
  </code></pre>
  
  <p>and here is code i trying to convert, i mean before it code html  as the output (ul>li>ul>li>/li>/ul>/li>/lu)</p>
  
  <pre><code>$id = '';
  function sub($items, $id){
      foreach($items as $item){
          if($item['parent_id'] == $id){
              return array("link" =&gt;$item['link'],"title"=&gt;$item['title']);
              sub($items, $item['id']);
          }
      }
  }
  foreach($allmenu as $data){
      if($data['parent_id'] == 0){
          $id = $data['id'];
          $utama[]= array("link"=&gt;$data['link'],"title"=&gt;$data['title'],"sub"=&gt;sub($allmenu, $id));
      }
  }
  </code></pre>
  
  <p>and this is the output from above code</p>
  
  <pre><code>Array
  (
      [links] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [link] =&gt; 1.html
                      [title] =&gt; Dashboard
                      [sub] =&gt; 
                  )
  
              [1] =&gt; Array
                  (
                      [link] =&gt; 2.html
                      [title] =&gt; Master Data
                      [sub] =&gt; Array
                          (
                              [link] =&gt; 11.html
                              [title] =&gt; Kampus
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  
  <p>see.. in 2nd array (master data) it should two array right? with link 11.html and 12.html.<br>
  if there is mistake from my code let me know, if there is link to do this job, let me know. thanks</p>