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) {
$result = [];
foreach ($elements as $element) {
if ($element['PARENT_ID'] == $parentId) {
$childs = self::create_tree_recursive($elements, $element['ID'], $level + 1);
foreach ($childs as $child) {
$result[] = $child;
}
$element['NAME_ru_ru'] = str_repeat('.', $level) . $element['NAME_ru_ru'];
$result[] = $element;
}
}
return $result;
}