使用 ThinkPHP 5.0 查询 menu 表中的树形结构,你可以使用以下方法:
- 使用
collection
方法将查询结果转换为集合,然后使用tree
方法将集合构建成树形结构:
$list = Db::name('menu')->field('id,pid,name')->select();
$tree = collection($list)->toArray();
$tree = \think\helper\Arr::tree($tree, 'name', 'id', 'pid');