first() public method

Get the first item from the collection.
public first ( Closure $callback = null, mixed $default = null ) : mixed | null
$callback Closure
$default mixed
return mixed | null
Example #1
0
 public function testFirstWithCallbackAndDefault()
 {
     $data = new Collection(array('foo', 'bar'));
     $result = $data->first(function ($key, $value) {
         return $value === 'baz';
     }, 'default');
     $this->assertEquals('default', $result);
 }