Advertisement
Guest User

PHP Category Iteration

a guest
May 23rd, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement