Recursive function getTitlesLineage()

This commit is contained in:
Miraty 2022-09-09 20:16:48 +02:00
parent 173f7b15d3
commit 21e20c9008

View file

@ -41,23 +41,19 @@ if (PAGE !== 'index') {
} }
} }
for ( function getTitlesLineage($titles, $pageElements) {
$path_i = PAGE_LINEAGE , $results = [] , $firstIteration = true ; if (!isset($titles['index']) OR $pageElements[0] === 'index')
$title = TITLES , $path_i !== [] ; return [$titles[$pageElements[0]]];
array_pop($path_i) , $results[] = $title $result = $titles['index'];
) { if (!isset($pageElements[1]))
foreach ($path_i as $el) { unset($titles['index']);
if (end($path_i) !== $el) else
$title = $title[$el]; $titles = $titles[array_shift($pageElements)];
else { $results = getTitlesLineage($titles, $pageElements);
if ($firstIteration AND end($path_i) !== 'index') $results[] = $result;
$results[] = $title[$el]; return $results;
$firstIteration = false;
$title = $title['index'];
}
}
} }
define('TITLES_LINEAGE', array_reverse($results)); define('TITLES_LINEAGE', array_reverse(getTitlesLineage(TITLES, PAGE_LINEAGE)));
require "html.php"; require "html.php";