refactor: 修改递归函数level计算错误

This commit is contained in:
2025-03-13 15:29:06 +08:00
parent 640d3afd53
commit 7a5df71aff

View File

@@ -15,11 +15,12 @@ if (!function_exists('array_to_tree')) {
$ret = []; $ret = [];
foreach ($data as $item) { foreach ($data as $item) {
if ($item[$with] == $pid) { if ($item[$with] == $pid) {
$lv = $level;
if ($level !== false) { if ($level !== false) {
$item['level'] = $level; $item['level'] = $level;
$level = $level + 1; $lv = $level + 1;
} }
$children = array_to_tree($data, $item['id'], $with, $level); $children = array_to_tree($data, $item['id'], $with, $lv);
if ($children) { if ($children) {
$item['children'] = $children; $item['children'] = $children;
} }