refactor: 修改用户菜单权限输出结构
This commit is contained in:
@@ -10,13 +10,16 @@ if (!function_exists('array_to_tree')) {
|
||||
* @param int $level 层级
|
||||
* @return array
|
||||
*/
|
||||
function array_to_tree(array $data, int $pid, string $with = 'pid', int $level = 1)
|
||||
function array_to_tree(array $data, int $pid, string $with = 'pid', int|false $level = 1)
|
||||
{
|
||||
$ret = [];
|
||||
foreach ($data as $item) {
|
||||
if ($item[$with] == $pid) {
|
||||
$item['level'] = $level;
|
||||
$children = array_to_tree($data, $item['id'], $with, $level + 1);
|
||||
if ($level !== false) {
|
||||
$item['level'] = $level;
|
||||
$level = $level + 1;
|
||||
}
|
||||
$children = array_to_tree($data, $item['id'], $with, $level);
|
||||
if ($children) {
|
||||
$item['children'] = $children;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user