title: php display multilevel treenode menu recursive
body: <p>I have a post regarding this which was answered though I now have a different problem related to the same topic. You may want to reference here for the original question. <a href="https://stackoverflow.com/questions/22752355/php-display-multilevel-treenode-menu">php display multilevel treenode menu</a></p>
  
  <p>Now that the array is displaying by tree-node, it seems that it is not fully recursive. I notice that when the first element is a child node, it is not displaying as a child.</p>
  
  <p>I tried doing a krsort then ksort.</p>
  
  <pre><code>function getChildren(&amp;$rows, $p = 0) {
      $r = array();
      krsort($rows);
      foreach($rows as $row_id =&gt; $row) {
          if ($row['parent_node']==$p) {
              $r[$row['product_category_code']] = getChildren($rows, $row['product_category_code']);
              unset($rows[$row_id]);
          }
      }
      ksort($rows);
      return $r;
  }
  </code></pre>
  
  <p>Here's the structure of the array:</p>
  
  <pre><code>array
    0 =&gt; 
      array
        'product_category_code' =&gt; string 'akamia' (length=6)
        'product_category_desc' =&gt; string 'Akamia' (length=6)
        'parent_node' =&gt; string 'summer-dress' (length=12)
        'inactive' =&gt; string '0' (length=1)
        'sort' =&gt; string '0' (length=1)
        'created_by' =&gt; string '1' (length=1)
        'created_date' =&gt; string '2014-04-01 10:03:42' (length=19)
        'modified_by' =&gt; string '1' (length=1)
        'modified_date' =&gt; string '2014-04-01 10:03:47' (length=19)
    1 =&gt; 
      array
        'product_category_code' =&gt; string 'bracelets' (length=9)
        'product_category_desc' =&gt; string 'Bracelets' (length=9)
        'parent_node' =&gt; string '' (length=0)
        'inactive' =&gt; string '0' (length=1)
        'sort' =&gt; string '0' (length=1)
        'created_by' =&gt; string '1' (length=1)
        'created_date' =&gt; string '2014-03-14 22:04:08' (length=19)
        'modified_by' =&gt; string '1' (length=1)
        'modified_date' =&gt; string '2014-03-14 22:09:05' (length=19)
    2 =&gt; 
      array
        'product_category_code' =&gt; string 'floral-dress' (length=12)
        'product_category_desc' =&gt; string 'Floral Dress' (length=12)
        'parent_node' =&gt; string '' (length=0)
        'inactive' =&gt; string '0' (length=1)
        'sort' =&gt; string '0' (length=1)
        'created_by' =&gt; string '1' (length=1)
        'created_date' =&gt; string '2014-03-14 22:09:49' (length=19)
        'modified_by' =&gt; string '1' (length=1)
        'modified_date' =&gt; string '2014-04-01 10:03:30' (length=19)
    3 =&gt; 
      array
        'product_category_code' =&gt; string 'flowery-bracelets' (length=17)
        'product_category_desc' =&gt; string 'Flowery Bracelets' (length=17)
        'parent_node' =&gt; string 'bracelets' (length=9)
        'inactive' =&gt; string '0' (length=1)
        'sort' =&gt; string '0' (length=1)
        'created_by' =&gt; string '1' (length=1)
        'created_date' =&gt; string '2014-03-14 22:09:16' (length=19)
        'modified_by' =&gt; string '1' (length=1)
        'modified_date' =&gt; string '2014-03-30 19:08:44' (length=19)
    4 =&gt; 
      array
        'product_category_code' =&gt; string 'small-flowery-bracelets' (length=23)
        'product_category_desc' =&gt; string 'Small Flowery Bracelets' (length=23)
        'parent_node' =&gt; string 'flowery-bracelets' (length=17)
        'inactive' =&gt; string '0' (length=1)
        'sort' =&gt; string '0' (length=1)
        'created_by' =&gt; string '1' (length=1)
        'created_date' =&gt; string '2014-03-14 22:08:35' (length=19)
        'modified_by' =&gt; string '1' (length=1)
        'modified_date' =&gt; string '2014-03-30 19:09:44' (length=19)
    5 =&gt; 
      array
        'product_category_code' =&gt; string 'summer-dress' (length=12)
        'product_category_desc' =&gt; string 'Summer Dress' (length=12)
        'parent_node' =&gt; string '' (length=0)
        'inactive' =&gt; string '0' (length=1)
        'sort' =&gt; string '0' (length=1)
        'created_by' =&gt; string '1' (length=1)
        'created_date' =&gt; string '2014-03-14 22:09:29' (length=19)
        'modified_by' =&gt; string '0' (length=1)
        'modified_date' =&gt; null
  </code></pre>
  
  <p>The output (without the krsort / ksort) is showing this, which is wrong:</p>
  
  <ul>
  <li>Akamai</li>
  <li>Bracelets
  
  <ul>
  <li>Flowery Bracelets
  
  <ul>
  <li>Small Flowery Bracelets</li>
  </ul></li>
  </ul></li>
  <li>Floral Dress</li>
  <li>Summer Dress</li>
  </ul>
  
  <p>This should be the output:</p>
  
  <ul>
  <li>Bracelets
  
  <ul>
  <li>Flowery Bracelets
  
  <ul>
  <li>Small Flowery Bracelets</li>
  </ul></li>
  </ul></li>
  <li>Floral Dress</li>
  <li>Summer Dress
  
  <ul>
  <li>Akamai</li>
  </ul></li>
  </ul>