$item) { if (isset($items[$item['pid']])) { $items[$item['pid']]['list'][] = &$items[$id]; } else { $tree[] = &$items[$id]; } } return $tree; } /** * 对前端的分类数目进行截取 * @param array $data * @param int $firstCount * @param int $secondCount * @param int $threeCount * @return array */ public static function sliceTreeArr(array $data, int $firstCount = 5, int $secondCount = 3, int $threeCount = 5): array { $data = array_slice($data, 0, $firstCount); foreach ($data as $k => $v) { if (!empty($v['list'])) { $data[$k]['list'] = array_slice($v['list'], 0, $secondCount); foreach ($v['list'] as $kk => $vv) { if (!empty($vv['list'])) { $data[$k]['list'][$kk]['list'] = array_slice($vv['list'], 0, $threeCount); } } } } return $data; } }