Let\'s dig in the main problem right away, I have the input like this
$category = array(
\'A\' => array(\'left\' => 1, \'right\' => 8),
\'B\' =&
If you dont want to use recursion:
foreach ($category as $name => $range) {
$line[$range['left']] = $name;
$line[$range['right']] = $name;
}
ksort($line);
$count = 0;
foreach($line as $name) {
if ( ! isset($open[$name])) {
$open[$name] = true;
$result[$name] = true;
$count++;
} else {
unset($open[$name]);
if ($count > 0) {
$count = 0;
$tree[] = array_keys($result);
$result = $open;
} else {
$result = array();
}
}
}