PHP 无限极分类列表
作者:程序员11 时间:2025-12-16 人气:5 QQ交流群\邮箱:1003265987@qq.com
PHP 无限极分类列表
要展示的内容
注意数组里面需要包含 pid、level、id这几个字段
/**
* 无限极分类列表
*/
if (!function_exists('get_cate_list')) {
//递归函数 实现无限级分类列表
function get_cate_list($list,$pid=0,$level=0) {
static $tree = array();//静态不会在递归的时候重复创建,之创建一次
foreach($list as $row) {
if($row['pid']==$pid) {
$row['level'] = $level;
$tree[] = $row;
get_cate_list($list, $row['id'], $level + 1);
}
}
return $tree;
}
}查询结果如下:
{
"code": 200,
"msg": "success",
"data": [
{
"id": 1,
"auth_name": "首页",
"pid": 0,
"pid_path": "0",
"auth_c": "",
"auth_a": "",
"is_nav": 1,
"level": 0
},
{
"id": 90,
"auth_name": "首页",
"pid": 1,
"pid_path": "0_1",
"auth_c": "",
"auth_a": "",
"is_nav": 1,
"level": 1
},
{
"id": 91,
"auth_name": "首页",
"pid": 90,
"pid_path": "0_1_90",
"auth_c": "index",
"auth_a": "index",
"is_nav": 1,
"level": 2
},
{
"id": 104,
"auth_name": "首页啊",
"pid": 90,
"pid_path": "0_1_90",
"auth_c": "s",
"auth_a": "y",
"is_nav": 1,
"level": 2
}
]
}
温馨提示:
欢迎阅读本文章,觉得有用就多来支持一下,没有能帮到您,还有很多文章,希望有一天能帮到您。
- 上一篇:php怎么快速添加注释快捷键
- 下一篇:PHP 父子级树状列表
