// 無限分類 function cateSort($data, $fid = 0, $count = 0) { static $arr = []; foreach ($data as $k => $v) { if ($v['fid'] == $fid) { $v['count'] = $count; $arr[] = $v; unset($data['$k']); cateSort($data, $v['id'], $count + 1); } } return $arr; }