php代码如下:
//模拟数据库
$data=array(
array('id'=>1,'pid'=>0,'name'=>'栏目一'),
array('id'=>2,'pid'=>1,'name'=>'子栏目'),
array('id'=>3,'pid'=>1,'name'=>'二级栏目一'),
array('id'=>4,'pid'=>3,'name'=>'三级栏目一'),
array('id'=>5,'pid'=>4,'name'=>'四级栏目一'),
array('id'=>6,'pid'=>0,'name'=>'一级栏目一'),
array('id'=>7,'pid'=>2,'name'=>'一级栏目二'),
array('id'=>8,'pid'=>1,'name'=>'二级栏目一'),
array('id'=>9,'pid'=>2,'name'=>'三级栏目一'),
array('id'=>10,'pid'=>3,'name'=>'四级栏目一'),
);
//转换数据
$tree_data=array();
foreach ($data as $key=>$value){
$tree_data[$value['id']]=array(
'id'=>$value['id'],
'parentid'=>$value['pid'],
'name'=>$value['name']
);
}
/**
* 输出树形结构
*/
$tree=new Tree();
$tree->init($tree_data);
echo "<div class='tree well'>";
echo $tree->get_treeview(0, $str);
echo "</div>";
海绵宝宝撒