public method

Rewinds the collection and returns the first item or when a filter is used, returns the first non-empty item after the filter is applied.


  • callable $filter

    An optional callable through which items will be passed. If the return value of this function is trueish, it will be returned as the result of the method call. An example filter function may look like: function($item) { return $item->year < 2005; }.



Returns the first item in the collection or when $filter is used, the first item where $filter returned a trueish result.


	public function first($filter = null) {
		if (!$filter) {
			return $this->rewind();
		foreach ($this as $item) {
			if ($filter($item)) {
				return $item;