title: How to add empty children array for the empty parents?
body: <p>I have a JSON populated output.
  Wherever the children are not available the children index is missing.</p>
  <pre><code>[7] =&gt; Array
  (   
      [id] =&gt; 171
      [text] =&gt; Some Text
      [groupid] =&gt; 170
      [leaf] =&gt; false
      [qtip] =&gt; Cool
  )
  </code></pre>
  <p>However, I need the children to be added with an empty array.</p>
  <pre><code>[7] =&gt; Array
  (   
      [id] =&gt; 171
      [text] =&gt; Some Text
      [groupid] =&gt; 170
      [leaf] =&gt; false
      [qtip] =&gt; Cool
      [children] =&gt; []
  )
  </code></pre>
  <p>Here is my code that creates the output:</p>
  <pre><code>$res = $dbConn-&gt;prepare($sql);
  $res-&gt;execute();
  $result = $res-&gt;fetchAll(PDO::FETCH_ASSOC);
  
      $tmpData = false;
      foreach ($result as $k =&gt; &amp;$val) {
          $tmpData[$val['id']] = &amp;$val;
      }
      
      foreach ($result as $k =&gt; &amp;$val) {
          if ($val['groupid'] &amp;&amp; isset($tmpData[$val['groupid']])) {
              $tmpData[$val['groupid']]['children'][] = &amp;$val;
          }
      }
      
      foreach ($result as $k =&gt; &amp;$val) {
          if ($val['groupid'] &amp;&amp; isset($tmpData[$val['groupid']])) {
              unset($result[$k]);
          }
      }
  </code></pre>