title: reindex a element of tree array php
body: <p>I tried so much codes but this one gave me a result close to what I want.
   I want to change the key of a child element in this case the second array 'eric'=>array into integer '0'=>array </p>
  
  <pre><code>while($d = mysqli_fetch_assoc($result)) {
      if(!isset($data[$d['country']])) {
         $data[$d['country']] = array(
           'text' =&gt; $d['country'],
           'nodes' =&gt; array()  
         ); 
      }
      if(!isset($data[$d['country']]['nodes'][$d['name']])) {
          $data[$d['country']]['nodes'] = array_values($data[$d['country']]['nodes']);
          $data[$d['country']]['nodes'][$d['name']] = array(
            'text' =&gt; $d['name'],
            'nodes' =&gt; array()
          );    
       }
      array_push($data[$d['country']]['nodes'][$d['name']]['nodes'], $d['n_doc']);
  }
  </code></pre>
  
  <p>but the first record with nodes does not take it .like as follow:</p>
  
  <pre><code>0 =&gt; Array
  ('text' =&gt; 'paris',
   'nodes' =&gt; Array
          ('0' =&gt; Array
                  (  'text' =&gt; 'eric',
                     'nodes' =&gt; Array
                         (0 =&gt; Array
                             (
                              'text' =&gt; 'so.png',              
                             ),
                          1 =&gt; Array
                             (
                              'text' =&gt; 'dd.png',              
                             ),
                          2 =&gt; Array
                             (
                              'text' =&gt; 'dd.png',              
                             ),
                         ),
                  ),
          ),
              ('charl' =&gt; Array
                  (  'text' =&gt; 'charl',
                     'nodes' =&gt; Array
                         (0 =&gt; Array
                             (
                              'text' =&gt; 'so.png',              
                             ),
                         ),
                  ),
          ),
  ),
  </code></pre>
  
  <p>anyone can tell me where is the problem.
   i want have array like this :</p>
  
  <pre><code>0 =&gt; Array
  ('text' =&gt; 'paris',
   'nodes' =&gt; Array
          ('0' =&gt; Array
                  (  'text' =&gt; 'eric',
                     'nodes' =&gt; Array
                         (0 =&gt; Array
                             (
                              'text' =&gt; 'so.png',              
                             ),
                          1 =&gt; Array
                             (
                              'text' =&gt; 'dd.png',              
                             ),
                          2 =&gt; Array
                             (
                              'text' =&gt; 'so.png',              
                             ),
                         ),
                  ),
          ),
        ('1' =&gt; Array
                  (  'text' =&gt; 'charl',
                     'nodes' =&gt; Array
                         (0 =&gt; Array
                             (
                              'text' =&gt; 'so.png',              
                             ),
                         ),
                  ),
          ),
  ),
  </code></pre>