function getTreeFromArray($data, $pid = 0, $key = 'id', $pKey = 'parent_id', $childKey = 'child', $maxDepth = 0, $level = 0) { static $depth = 0; $depth++; $level++; $tree = array(); if (intval($maxDepth) <= 0) { $maxDepth = count($data) * count($data); } if ($maxDepth == 1) { $data[0]['level'] = $level; return $data; } if ($depth > $maxDepth) { } foreach ($data as $rk => $rv) { if ($rv[$pKey] == $pid) { $rv['level'] = $level; $rv[$childKey] = getTreeFromArray($data, $rv[$key], $key, $pKey, $childKey, $maxDepth, $level); $tree[] = $rv; } } return $tree; }
无限极分类
最新推荐文章于 2022-06-01 17:38:29 发布