コード例 #1
0
ファイル: SupportArrTest.php プロジェクト: stillat/collection
 public function testFirst()
 {
     $array = [100, 200, 300];
     $value = Arr::first($array, function ($key, $value) {
         return $value >= 150;
     });
     $this->assertEquals(200, $value);
 }
コード例 #2
0
ファイル: Collection.php プロジェクト: stillat/collection
 /**
  * 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);
 }