当前位置: 首页 > article >正文

PHP三级分类数据处理

一、原始数据

function getDatas(){
    return [
	[
		'component' => 'system',
		'redict' => '/system',
		'path' => '/system',
		'hidden' => 1,
		'name' => '系统管理',
		'children' => [
			[
				'component' => 'user',
				'redict' => '/user',
				'path' => '/user',
				'hidden' => 1,
				'name' => '用户管理',
				'children' => [
					[
						'component' => 'user_list',
						'redict' => '/user_list',
						'path' => '/user_list',
						'hidden' => 1,
						'name' => '用户列表',
					],
					[
						'component' => 'role',
						'redict' => '/user_role',
						'path' => '/user_role',
						'hidden' => 1,
						'name' => '角色列表',
					],
					[
						'component' => 'perm',
						'redict' => '/perm',
						'path' => '/perm',
						'hidden' => 1,
						'name' => '权限列表',
					],
				]
			],
			[
				'component' => 'data',
				'redict' => '/data',
				'path' => '/data',
				'hidden' => 1,
				'name' => '数据管理',
				'children' => [
					[
						'component' => 'report',
						'redict' => '/report',
						'path' => '/report',
						'hidden' => 1,
						'name' => '分日报表',
					],
					[
						'component' => 'hour_report',
						'redict' => '/hour_report',
						'path' => '/hour_report',
						'hidden' => 1,
						'name' => '分时报表',
					],
					[
						'component' => 'month_report',
						'redict' => '/month_report',
						'path' => '/month_report',
						'hidden' => 1,
						'name' => '分月报表',
					],
				]
			],
			[
				'component' => 'resource',
				'redict' => '/resource',
				'path' => '/resource',
				'hidden' => 1,
				'name' => '资源管理',
				'children' => [
					[
						'component' => 'res_list',
						'redict' => '/res_list',
						'path' => '/res_list',
						'hidden' => 1,
						'name' => '资源列表'
					]
				]
			]
		]
	]
]
}

二、函数处理

function deal(){
        $datas = getDatas();
        $level_1_tree = [];
        foreach($datas as $data_level_1){
            $data_level_1_arr['component'] = $data_level_1['component'];
            $data_level_1_arr['redict'] = $data_level_1['redict'];
            $data_level_1_arr['path'] = $data_level_1['path'];
            $data_level_1_arr['meta'] = [
                 'title' => $data_level_1['name'],
                 'hidden' => $data_level_1['hidden']
            ];
            $level_2_tree = [];
            if(isset($data_level_1['children']) && !empty($data_level_1['children'])) {
                foreach ($data_level_1['children'] as $data_level_2) {
                    $data_level_2_arr['component'] = $data_level_2['component'];
                    $data_level_2_arr['redict'] = $data_level_2['redict'];
                    $data_level_2_arr['path'] = $data_level_2['path'];
                    $data_level_2_arr['meta'] = [
                     'title' => $data_level_2['name'],
                     'hidden' => $data_level_2['hidden']
                    ];
                    $level_3_tree = [];
                    if (isset($data_level_2['children']) && !empty($data_level_2['children'])) {
                       
                       foreach ($data_level_2['children'] as $data_level_3) {
                            $data_level_3_arr['component'] = $data_level_3['component'];
                            $data_level_3_arr['redict'] = $data_level_3['redict'];
                            $data_level_3_arr['path'] = $data_level_3['path'];
                            $data_level_3_arr['meta'] = [
                               'title' => $data_level_3['name'],
                               'hidden' => $data_level_3['hidden']
                            ];
                            array_push($level_3_tree, $data_level_3_arr);
                            unset($data_level_3_arr);
                       }
                       $data_level_2_arr['children'] = $level_3_tree;
                    }
                    array_push($level_2_tree, $data_level_2_arr);
                    unset($data_level_2_arr);
                }
                $data_level_1_arr['children'] = $level_2_tree;
            }
            
            array_push($level_1_tree, $data_level_1_arr);
            unset($data_level_1_arr);
        }
        print_r($level_1_tree);
    }

  deal();



http://www.kler.cn/a/228080.html

相关文章:

  • Unity 粒子特效在UI中使用裁剪效果
  • 设计模式的艺术-策略模式
  • SpringCloud基础二(完结)
  • 【深度学习】 UNet详解
  • 关于opencv环境搭建问题:由于找不到opencv_worldXXX.dll,无法执行代码,重新安装程序可能会解决此问题
  • 1.26学习
  • eslint报错文档大量红色报错符号 不自动修正
  • ERP 系统架构的设计与实践总结
  • 课时14:变量基础_变量定义
  • 蓝桥杯第八届省赛题笔记------基于单片机的电子钟程序设计与调试
  • 【华为】GRE VPN 实验配置
  • 彻底学会系列:一、机器学习之线性回归
  • scikit-learn 1.3.X 版本 bug - F1 分数计算错误
  • 【MATLAB源码-第135期】基于matlab的变色龙群优化算法CSA)机器人栅格路径规划,输出做短路径图和适应度曲线。
  • 跟着cherno手搓游戏引擎【20】混合(blend)
  • 全流程机器视觉工程开发(四)PaddleDetection C++工程化应用部署到本地DLL以供软件调用
  • 线性表 —— 数组、栈、队、链表
  • 【SparkML实践7】特征选择器FeatureSelector
  • Redis实现:每个进程每30秒执行一次任务
  • Tomcat组件架构与数据流
  • 04.PostgreSQL多表查询
  • ffmpeg的使用,安装,抽帧,加水印,截图,生成gif,格式转换,抓屏等
  • 简单介绍Spring Security 的认证机制和授权机制
  • 鸿蒙(HarmonyOS)项目方舟框架(ArkUI)之Menu组件
  • Leetcode—38. 外观数列【中等】
  • 微信小程序编译出现 project.config.json 文件内容错误