为了账号安全,请及时绑定邮箱和手机立即绑定

权限列表的循环

权限列表的循环

PHP
红颜莎娜 2019-03-18 15:36:51
如题我有一个查询会查出当前用户所有的权限 $authList = [ ['id' => 1, 'pid' => 0, 'title' => 'project'], ['id' => 2, 'pid' => 0, 'title' => 'customer'], ['id' => 3, 'pid' => 1, 'title' => 'select'], ['id' => 4, 'pid' => 1, 'title' => 'delete'], ['id' => 5, 'pid' => 2, 'title' => 'select'], ['id' => 6, 'pid' => 2, 'title' => 'delete'], ['id' => 7, 'pid' => 6, 'title' => 'logic delete'] ]; 我想重新组织这个数组使它根据pid变成树形结构,就像这样 $result = [ [ 'id' => 1, 'pid' => 0, 'title' => 'project', 'children' => [ [ 'id' => 3, 'pid' => 1, 'title' => 'select' ], [ 'id' => 4, 'pid' => 1, 'title' => 'delete' ], ] ], [ [ 'id' => 2, 'pid' => 0, 'title' => 'customer', 'children' => [ [ 'id' => 5, 'pid' => 2, 'title' => 'select' ], [ 'id' => 6, 'pid' => 2, 'title' => 'delete', 'children' => [ [ 'id' => 7, 'pid' => 6, 'title' => 'logic delete' ] ], ] ], ], ], ]; 请问大家有没有什么要率高的算法?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 353 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信