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; }