Let\'s dig in the main problem right away, I have the input like this
$category = array(
\'A\' => array(\'left\' => 1, \'right\' => 8),
\'B\' =&
I little modified Stiven's code.
public function createTree($category, $left = 0, $right = null) {
$tree = array();
foreach ($category as $cat => $range) {
if ($range['clf'] == $left + 1 && (is_null($right) || $range['crt'] < $right)) {
$tree[$cat]= array();
$tree[$cat]['title']=$range['title'];
if($range['crt']-$range['clf']>1){
$tree[$cat]['sub'] = $this->createTree($category, $range['clf'], $range['crt']);
}
$left = $range['crt'];
}
}
return $tree;
}