Extends
lithium\core\Object
Returns the first non-empty value in the collection after a filter is applied, or rewinds the
collection and returns the first value.
Parameters
- callback $filter A closure through which collection values will be passed. If the return value of this function is non-empty, it will be returned as the result of the method call. If `null`, the collection is rewound (see `rewind()`) and the first item is returned.
Returns
mixed Returns the first non-empty collection value returned from `$filter`.Source
public function first($filter = null) {
if (!$filter) {
return $this->rewind();
}
foreach ($this as $item) {
if ($filter($item)) {
return $item;
}
}
}