在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/** * 递归权限(数组) * * @param $data select查询来未处理过的数组 * @param $pid * @return array */ function recursiveMenuArray($data,$pid){ $re_data =[]; foreach ($data as $key=>$value){ if($value['pid'] == $pid){ $re_data[$value['id']] = $value; $re_data[$value['id']]['list'] = $this->recursionMenu($data,$value['id']); }else{ continue; } } return $re_data; } $data = query("select * from menu");//二维数组 $array = recursiveMenuArray($data,0); print_r($array);
输出结果: Array ( [1] => Array ( [id] => 1 [title] => 操作员列表 [pid] => 0 [list] => Array ( [2] => Array ( [id] => 2 [title] => 在线配置 [pid] => 1 [list] => Array ( [3] => Array ( [id] => 3 [title] => 服务器信息 [pid] => 2 [list] => Array ( [4] => Array ( [id] => 4 [title] => 游戏账号 [pid] => 3 [list] => Array ( ) ) [5] => Array ( [id] => 5 [title] => 查询 [pid] => 3 [list] => Array ( ) ) [6] => Array ( [id] => 6 [title] => 邮件及兑换码 [pid] => 3 [list] => Array ( ) ) ) ) ) ) ) ) )
|
2022-07-18
2022-08-30
2022-08-17
2022-11-06
2022-08-17
请发表评论