This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

PHP Category Iteration

By: a guest on May 23rd, 2012  |  syntax: PHP  |  size: 0.43 KB  |  views: 84  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data