lithium\util\Collection::first()
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.
Parameters
-
callable
$filterAn 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
mixedReturns the first item in the collection or when $filter is used,
the first item where $filter returned a trueish result.
Source
public function first($filter = null) {
if (!$filter) {
return $this->rewind();
}
foreach ($this as $item) {
if ($filter($item)) {
return $item;
}
}
}