public function getAreaTree($code)
{
$where = '';
if ($code){
$where = ['b.code' => $code];
}
$info = Db::table('__AREA__ a')
->join('__AREA__ b','a.p_code = b.code','left')
->field('a.id,a.code as v,a.name as n,a.p_code,b.name as p_name')->where($where)->select();
if(!empty($info)){
$info = array_column($info,null,'v');
$info = $this->generateTreeback($info);
}
return $info;
}
function generateTreeback($items,$field = 'v', $pfield = 'p_code', $child = 'c')
{
$tree = [];
foreach($items as $item){
if(isset($items[$item[$pfield]])){
$items[$item[$pfield]][$child][] = &$items[$item[$field]];
}else{
$tree[] = &$items[$item[$field]];
}
}
return $tree;
}
---------------------
作者:是后海大鲨鱼
来源:CSDN
原文:https://blog.csdn.net/qq_36647209/article/details/88824287
版权声明:本文为博主原创文章,转载请附上博文链接!