public static function tree($nodes, $parent_id = 0, $level = 0, $increment_id_name = "id", $parent = "parent_id")
{
$tree = array();
$level++;
foreach ($nodes as $node) {
if ($node[$parent] == $parent_id) {
$children = self::tree($nodes, $node[$increment_id_name],$level,$increment_id_name,$parent);
if($children){
$node['children'] = $children;
}
$node['level'] = $level;
$tree[] = $node;
}
}
return sizeof($tree)?$tree:false;
}