SHARE
TWEET

PHP Category Iteration

a guest May 23rd, 2012 98 Never
  1. $catrefs = array();
  2. $catlist = array();
  3. foreach($categories as $tmp) {
  4.        
  5.         $thisref = &$catrefs[ $tmp['id'] ];
  6.         $thisref['parent_id'] = $tmp['parent'];
  7.         $thisref['name'] = $tmp['name'];
  8.         $thisref['products'] = $tmp['products'];
  9.         $thisref['totals'] = $tmp['products'];
  10.        
  11.         if($tmp['parent'] == 0) {
  12.  
  13.                 $catlist[ $tmp['id'] ] = & $thisref;
  14.         }
  15.         else {
  16.  
  17.                 $catrefs[ $tmp['parent'] ]['children'][ $tmp['id'] ] = &$thisref;
  18.         }
  19. }
RAW Paste Data
Top