$array = array('a', 'b', 'c'); $last = Arrays::last($array);
c
/** * @return Event[] */ public static function loadNew() { $lastEventId = Session::get('last_event_id'); if (!$lastEventId) { //do not load events that we triggered before this session was started /** @var Event $lastEvent */ $lastEvent = Event::queryBuilder()->limit(1)->order('id desc')->fetch(); Session::set('last_event_id', $lastEvent ? $lastEvent->id : 0); } $events = Event::where(['id' => Restrictions::greaterThan($lastEventId)])->order('id asc')->fetchAll(); if ($events) { Session::set('last_event_id', Arrays::last($events)->id); } return $events; }
/** * @test * @expectedException \InvalidArgumentException */ public function shouldThrowExceptionWhenElementsAreEmptyInLast() { //given $array = array(); //when Arrays::last($array); }