Back to PhocacartCategory class

Method categoryTree

public static
categoryTree
(mixed $d, mixed $r = 0, mixed $pk = 'parent_id', mixed $k = 'id', mixed $c = 'children')

Method categoryTree - Source code

public static function categoryTree($d, $r = 0, $pk = 'parent_id', $k = 'id', $c = 'children')
{
    $m = array();
    foreach ($d as $e) {
        isset($m[$e[$pk]]) ?: ($m[$e[$pk]] = array());
        isset($m[$e[$k]]) ?: ($m[$e[$k]] = array());
        $m[$e[$pk]][] = array_merge($e, array($c => &$m[$e[$k]]));
    }
    //return $m[$r][0]; // remove [0] if there could be more than one root nodes
    if (isset($m[$r])) {
        return $m[$r];
    }
    return 0;
}