获取树状分类结构
程序员文章站
2022-05-03 17:34:07
...
php代码
/** * @param $data//数据集合 * @param $pid * * @return array|string */ public function getTree($data, $pid) { $tree = array(); foreach ($data as $k => $v) { if ($v['parent_id'] == $pid) { $child = $this->getTree($data, $v['id']); if ($child) { $v['childs'] = $child; } $tree[] = $v; } } return $tree; }