public function sorts($data, $pid = 0, $level = 0){
static $arr = array();
foreach ($data as $k => $v) {
if ($v['parent_id'] == $pid) {
$v['level'] = $level;
$arr[$v['id']] = $v;
$this->sorts($data, $v['id'], $level + 1);
}
}
return $arr;
}
public function getTree($arr){
$tree = array();
foreach ($arr as $key => $value){
if (isset($arr[$value['parent_id']])){
$arr[$value['parent_id']]['children'][] =& $arr[$value['id']];
}else{
$tree[] =& $arr[$value['id']];
}
}
return $tree ;
}
分类
最新推荐文章于 2024-01-31 20:05:12 发布