title: Convert PHP array to JSON tree
body: <p>I have got a array in this format:</p>
  
  <pre><code>array(
      array('id' =&gt; 1, 'parent_id' =&gt; null, 'name' =&gt; 'lorem ipsum'),
      array('id' =&gt; 2, 'parent_id' =&gt; 1, 'name' =&gt; 'lorem ipsum1'),
      array('id' =&gt; 3, 'parent_id' =&gt; 1, 'name' =&gt; 'lorem ipsum2'),
      array('id' =&gt; 4, 'parent_id' =&gt; 2, 'name' =&gt; 'lorem ipsum3'),
      array('id' =&gt; 5, 'parent_id' =&gt; 3, 'name' =&gt; 'lorem ipsum4'),
      array('id' =&gt; 6, 'parent_id' =&gt; null, 'name' =&gt; 'lorem ipsum5'),
  );
  </code></pre>
  
  <p>I have to convert this array to json object with this style:</p>
  
  <pre><code>var json = {  
      id: "1",  
      name: "loreim ipsum",  
      data: {},  
      children: [{  
          id: "2",  
          name: "lorem ipsum1",  
          data: {},  
          children: [{  
              id: "3",  
              name: "lorem ipsum2",  
              data: {},  
              children: [{
              ..............
  </code></pre>
  
  <p>How can i do this? Thanks.</p>