Let\'s dig in the main problem right away, I have the input like this
$category = array(
\'A\' => array(\'left\' => 1, \'right\' => 8),
\'B\' =&
There is a bug with above function. The top category of second array of the @tree is removed. This is the fix:
foreach ($category as $name => $range) {
$line[$range['left']] = $name;
$line[$range['right']] = $name;
}
ksort($line);
$tree = array();
$count = 0;
foreach ($line as $name) {
if (!isset($open[$name])) {
$open[$name] = true;
$count++;
}
else {
if ($count > 0) {
$count = 0;
$tree[] = array_keys($open);
}
unset($open[$name]);
}
}