protected function outputTree($data, $depth = 0, $last_status = [])
{
if (!is_array($data) || empty($data)) {
return;
}
ksort($data);
// Record last name
foreach ($data as $name => $node) {
if ($depth == 0 && !$node['topentry']) {
continue;
}
$lastname = $name;
}
foreach ($data as $name => $node) {
if ($depth == 0 && !$node['topentry']) {
continue;
}
$is_last = $name == $lastname;
// Padding
$padding = '';
for ($i = 0; $i < $depth; $i++) {
if ($last_status[$i]) {
$padding .= ' ';
} else {
$padding .= '| ';
}
}
$padding .= ($is_last ? '`' : '|') . '-- ';
// Output
echo $padding . $name . "\n";
if ($node['children']) {
$last_status[$depth] = $is_last;
$this->outputTree($node['children'], $depth + 1, $last_status);
}
}
}