johno
|- matell
| L- joky
| |- alca
| |- sona
| | L- xfish5
| L- eva
L- droopy
L- tomo
Grafick‚ koment re
|- RE: Grafick‚ koment re
| L- RE: RE: Grafick‚ koment re
| |- RE: RE: RE: Grafick‚ koment re
| |- RE: RE: RE: Grafick‚ koment re
| | |- RE: RE: RE: RE: Grafick‚ koment re
| | L- RE: RE: RE: RE: Grafick‚ koment re
| | L- RE: RE: RE: RE: Grafick‚ koment re
| L- RE: RE: RE: Grafick‚ koment re
| |- RE: RE: RE: RE: Grafick‚ koment re
| L- RE: RE: RE: RE: Grafick‚ koment re
L- RE: Grafick‚ koment re
L- RE: RE: Grafick‚ koment re
<?php
$children = array(
0 => array(1, 2),
1 => array(3),
2 => array(4),
3 => array(5, 6, 7),
6 => array(8)
);
$text = array(
0 => 'johno',
1 => 'matell',
2 => 'droopy',
3 => 'joky',
4 => 'tomo',
5 => 'alca',
6 => 'sona',
7 => 'eva',
8 => 'xfish5',
);
function renderPartialTree($id = 0, $context = array(), $parentLast = true) {
global $children, $text; // nikto nevidi ;-) toto riesenie je len na ukazku algoritmu
echo implode('', $context).$text[$id]."\n";
$childs = array_key_exists($id, $children) ? $children[$id] : array();
array_pop($context);
foreach($childs as $position => $childId) {
$newContext = $context;
$last = ($position == (count($childs) - 1));
if($id) { // mimo kmena stromu
if(!$parentLast) {
$newContext[] = '| ';
} else {
$newContext[] = ' ';
}
}
if(!$last) {
$newContext[] = '|- ';
} else {
$newContext[] = 'L- ';
}
renderPartialTree($childId, $newContext, $last);
}
}
echo '<pre>';
renderPartialTree();
echo '</pre><hr /><pre>';
$children = array(
0 => array(1, 2),
1 => array(3),
2 => array(4),
3 => array(5, 6, 7),
7 => array(9, 12),
6 => array(8, 10),
10 => array(11),
);
$text = array(
0 => 'Grafick‚ koment re',
1 => 'RE: Grafick‚ koment re',
2 => 'RE: Grafick‚ koment re',
3 => 'RE: RE: Grafick‚ koment re',
4 => 'RE: RE: Grafick‚ koment re',
5 => 'RE: RE: RE: Grafick‚ koment re',
6 => 'RE: RE: RE: Grafick‚ koment re',
7 => 'RE: RE: RE: Grafick‚ koment re',
8 => 'RE: RE: RE: RE: Grafick‚ koment re',
9 => 'RE: RE: RE: RE: Grafick‚ koment re',
10 => 'RE: RE: RE: RE: Grafick‚ koment re',
11 => 'RE: RE: RE: RE: Grafick‚ koment re',
12 => 'RE: RE: RE: RE: Grafick‚ koment re',
);
renderPartialTree();
echo '</pre><hr />';
highlight_file(__FILE__);
?>