From 1732106e7b3022d026bc07a5e10afe39cd3f4117 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Mon, 14 Apr 2025 07:23:12 +0200 Subject: [PATCH] feat: Sort tree --- src/Controller/MainController.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 59d220e..f7650db 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -78,6 +78,8 @@ final class MainController extends AbstractController } } + self::ksort_recursive($tree); + return $this->render('main/index.html.twig', [ 'path' => $path, 'contents' => $text, @@ -113,4 +115,15 @@ final class MainController extends AbstractController 'text' => $nextIteration['text'], ]; } + + private static function ksort_recursive(array &$array, int $sort_flags = SORT_REGULAR): void + { + ksort($array, $sort_flags); + + foreach ($array as &$value) { + if (is_array($value)) { + self::ksort_recursive($value, $sort_flags); + } + } + } }