由于这个东西虽然不难, 但是每次都写也费劲, 所以记录一个...以后直接复制粘贴..改一改就完事了
/** * 获得树形结构的数据 * @param array $data * @param int $pid * @return array */function getTree(&$data = [], $pid = 0){ $tree = []; foreach ($data as $key => $value) { if ($value['pid'] == $pid) { $value['subArea'] = self::getTree($data, $value['id']); $tree[] = $value; } } return $tree;}