php基础递归

public function getViewSonIds($viewIds = [], $isp_ids = [])
    {
        static $allIds = [];
        $viewModel = ViewModel::query();

        if (empty($viewIds)) {
            return [];
        }

        if (!empty($isp_ids)) {
            $viewModel->whereIn('isp_id', $isp_ids);
        }

        $sonIds = $viewModel->whereIn('parent', $viewIds)->get()->pluck('id')->toArray();
        $allIds = array_merge($allIds, $sonIds);
        if (!empty($sonIds)) {
            $this->getViewSonIds($sonIds, $isp_ids);
        }

        return array_merge($viewIds, $allIds);
    }

 

你可能感兴趣的:(php)