$item, 'path' => $itemRelativePath, 'pdf_count' => $pdfCount, 'children' => scanFolders($fullPath, $itemRelativePath) ]; } } usort($items, fn($a, $b) => strcmp($a['text'], $b['text'])); return $items; } echo json_encode([ 'success' => true, 'folders' => scanFolders($basePath) ]);