Cakephp 3:收集到中间数组实体

Cakephp 3: Collections getting to middle array entities

我正在尝试构建一个视图,以在图表中显示最近(现在是四年,但最终是五年)的数据。我能够在显示最近 4 年的变量中成功提取数据(我还没有数据库中的第五年)。为了将其分解为视图并在关联数组上添加一些计算,我创建了一个集合。我可以找到第一个和最后一个数组实体,但不知道如何拆分中间的两个数组。

public function viewAsuFiveYear()
    {
        $asuFiveYearEnrollments = $this->Enrollments->find('all', [
            'contain' => ['Azinstitutions', 'FallFtes', 'FallHeadcounts', 'ProjectedEnrollments', 
                'FallHeadcounts.Locations', 'FallHeadcounts.StudentTypes', 'FallHeadcounts.ResidentStatuses', 'FallHeadcounts.Campuses',
                'FallFtes.Locations', 'FallFtes.StudentTypes', 'FallFtes.ResidentStatuses', 'FallFtes.Campuses']
        ], ['limit' => 5])->where(['azinstitution_id' => 1])->order(['enrollment_year' => 'DESC']);

       $collection = new Collection($asuFiveYearEnrollments);
       $yearone = $collection->first();
       $yearTwo = $collection->take(1, 1);
       $yearFour = $collection->last();

       $collection1HC = new Collection($yearone->fall_headcounts);
       $onCampusesHc1 = $collection1HC->match(['location_id' => 1 ])->match(['campus_id' => NULL]);
       $collection4HC = new Collection($yearFour->fall_headcounts);
       $onCampusesHc4 = $collection4HC->match(['location_id' => 1 ])->match(['campus_id' => NULL]);
       $this->set(compact('asuFiveYearEnrollments', 'azinstitutions', 'yearone', 'yearTwo', 'yearFour', 'onCampusesHc1', 'onCampusesHc4'));
    }

我试过 ->take(一个数组,第二个位置)但是它超时了。不确定我可以使用什么过滤器来获取第二个或第三个实体数组。

我相信我已经弄明白了。可能不是最好的答案,但它确实有效。第二年,我跳过了第一个阵列,抓住了剩下的第一个阵列。 第三年也一样

$yearTwo = $collection->skip(1)->first();
$yearThree = $collection->skip(2)->first();