public function testFirst() { $array = [100, 200, 300]; $value = Arr::first($array, function ($key, $value) { return $value >= 150; }); $this->assertEquals(200, $value); }
/** * Get the first item from the collection. * * @param callable|null $callback * @param mixed $default * * @return mixed */ public function first(callable $callback = null, $default = null) { if (is_null($callback)) { return count($this->items) > 0 ? reset($this->items) : null; } return Arr::first($this->items, $callback, $default); }