title: Parse multi-dimensional json array in JQuery
body: <p>I am pulling through json arrays into Jquery - no problem, just how do you parse a multi-dimensional array where you might have "children" arrays.</p>
  
  <p>PHP to "create" the json pulling from a database </p>
  
  <pre><code>   $STH = $DBH-&gt;query("SELECT FID FROM flist WHERE ParentID='0'" );
  $STH-&gt;setFetchMode(PDO::FETCH_OBJ);
  while( $row = $STH-&gt;fetch()) : 
   $farray[$row-&gt;FID]['FID']  = $row-&gt;FID;
    $RTH = $DBH-&gt;query("SELECT FID FROM flist WHERE ParentID= ".$row-&gt;FID." " );
    $RTH-&gt;setFetchMode(PDO::FETCH_OBJ);
    $fquerycount = $RTH-&gt;rowCount();
    if($fquerycount!=0): 
     while( $res = $RTH-&gt;fetch()) : 
      $farray[$row-&gt;FID]['FCHILD'][$res-&gt;FID] = $res-&gt;FID;
     endwhile;
    endif;
  endwhile;
  </code></pre>
  
  <p>encode it thus:</p>
  
  <pre><code>echo  $jc . '(' . json_encode($forum)  . ')';
  </code></pre>
  
  <p>Note: $jc is a jsoncallback.</p>
  
  <p>Now how do you "read" it here: </p>
  
  <pre><code>   $.getJSON("http://127.0.1/jtest3.php?start=0&amp;jsoncallback=?", function(data){ 
  $.each(data, function(i,item){         
  $('#testit').append('&lt;li'+item.FID+'&lt;ul&gt;&lt;li&gt;'+item.FCHILD+'&lt;/li&gt;&lt;ul&gt;&lt;/li&gt;');
  }); 
  });
  </code></pre>
  
  <p>It seems to me - OK I'm sure it must need - another .each() loop for the child array?  The code works OK for all aspects other than displaying the child.  If I remove the [$res->FID] key from the child array then that is OK but obviously I only get the last DB entry, The problem is that the child array is more than 1 entry.  You will have 1 parent (the first query that produces <code>$farray[$row-&gt;FID]['FID']  = $row-&gt;FID;</code>) then children the second query i.e. <code>$farray[$row-&gt;FID]['FCHILD'][$res-&gt;FID] = $res-&gt;FID;</code> Now there could be 2, 10, 20 etc. in this array.  How do you run that second each loop?  Help much appreciated.  Thanks</p>