public static function create_tree_recursiv array elements parentId le

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
public static function create_tree_recursive(array $elements, $parentId = 0, $level = 0) {
$branch = array();
foreach ($elements as $element) {
if ($element['PARENT_ID'] == $parentId) {
$children = self::create_tree_recursive($elements, $element['ID'], $level++);
if ($children) {
$element['children'] = $children;
}
$element['NAME_ru_ru'] = str_repeat('.', $level) . $element['NAME_ru_ru'];
$branch[] = $element;
}
}
return $branch;
}