$children) { $tree = array_merge($tree, $this->searchChildren($children, $root)); } echo '
'; echo ''; echo ''; } private function searchChildren(array $folders, string $root): array { $tree = []; $tree[$root] = []; foreach ($folders as $folder) { $folder = trim(str_replace($root, '', $folder), '/\\'); if (empty($folder)) { continue; } $pathParts = explode('/', $folder); $variable = &$tree[$root]; foreach ($pathParts as $pathPart) { if (empty($variable[$pathPart])) { $variable[$pathPart] = []; } $variable = &$variable[$pathPart]; } } return $tree; } private function displayTree(array $tree, string $pathValue, string $path = ''): void { if (empty($tree)) { return; } echo ''; } }