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 (
$path_i = PAGE_LINEAGE , $results = [] , $firstIteration = true ;
$title = TITLES , $path_i !== [] ;
array_pop($path_i) , $results[] = $title
) {
foreach ($path_i as $el) {
if (end($path_i) !== $el)
$title = $title[$el];
else {
if ($firstIteration AND end($path_i) !== 'index')
$results[] = $title[$el];
$firstIteration = false;
$title = $title['index'];
}
}
function getTitlesLineage($titles, $pageElements) {
if (!isset($titles['index']) OR $pageElements[0] === 'index')
return [$titles[$pageElements[0]]];
$result = $titles['index'];
if (!isset($pageElements[1]))
unset($titles['index']);
else
$titles = $titles[array_shift($pageElements)];
$results = getTitlesLineage($titles, $pageElements);
$results[] = $result;
return $results;
}
define('TITLES_LINEAGE', array_reverse($results));
define('TITLES_LINEAGE', array_reverse(getTitlesLineage(TITLES, PAGE_LINEAGE)));
require "html.php";