//返回无限级分类菜单
function get_cate_list($list,$pid=0,$html = '--',$f=0){
//声明一个静态数组存储处理后的数据
static $arr = [];
foreach($list as $val){
if($val['pid']==$pid){
$val['html'] = str_repeat($html, $f * 2);
$val['level'] = $f;
$arr[]=$val;
get_cate_list($list,$val['id'],$f+1);
}
}
return $arr;
}
实现父子级树状结构
function get_tree_list($list){
//将每条数据中的id值作为其下标
$temp = [];
foreach($list as $v){
$v['son'] = [];
$temp[$v['id']] = $v;
}
//获取分类树
foreach($temp as $k=>$v){
$temp[$v['pid']]['son'][] = &$temp[$v['id']];
}
return isset($temp[0]['son']) ? $temp[0]['son'] : [];
}
普通递归数据
function permission($data,$pid = 0)
{
$result = [];
if(empty($data))
{
return $result;
}
foreach ($data as $v){
if($v['pid'] == $pid){
$v['child'] = permission($data,$v['nid']);//$v['nid'] 为权限id
$result[] = $v;
}
}
return $result;
}