
PHP Category Iteration
By: a guest on
May 23rd, 2012 | syntax:
PHP | size: 0.43 KB | hits: 59 | expires: Never
$catrefs = array();
$catlist = array();
foreach($categories as $tmp) {
$thisref = &$catrefs[ $tmp['id'] ];
$thisref['parent_id'] = $tmp['parent'];
$thisref['name'] = $tmp['name'];
$thisref['products'] = $tmp['products'];
$thisref['totals'] = $tmp['products'];
if($tmp['parent'] == 0) {
$catlist[ $tmp['id'] ] = & $thisref;
}
else {
$catrefs[ $tmp['parent'] ]['children'][ $tmp['id'] ] = &$thisref;
}
}