$hierarchy * @var string $prefix * @var Tree $tree */ preg_match_all('/^(\d+) (\w+) ?(.*)/m', $gedcom, $matches); [, $levels, $tags, $values] = $matches; $levels = array_map(static fn (string $x): int => (int) $x, $levels); $keys = array_keys($levels); $elements = []; $ids = []; $indent = []; $collapse = []; foreach ($keys as $num => $key) { $hierarchy[$levels[$key]] = $tags[$key]; $elements[$key] = Registry::elementFactory()->make(implode(':', array_slice($hierarchy, 0, 1 + $levels[$key]))); $ids[$key] = Registry::idFactory()->id() . '-' . implode('-', array_slice($hierarchy, 0, 1 + $levels[$key])); // Does this element have any children? $has_subtags = ($levels[$key + 1] ?? 0) > $levels[$key]; // Do these children have values? $has_subtags_with_values = false; for ($n = $key + 1; $n < count($keys) && $levels[$n] > $levels[$key]; ++$n) { if ($values[$n] !== '') { $has_subtags_with_values = true; break; } } $indent[$key] = $elements[$key]->collapseChildren() && $has_subtags; $collapse[$key] = $num > 0 && $indent[$key] && !$has_subtags_with_values; } ?>