コード例 #1
0
ファイル: SupportArrTest.php プロジェクト: stillat/collection
 public function testLast()
 {
     $array = [100, 200, 300];
     $last = Arr::last($array, function () {
         return true;
     });
     $this->assertEquals(300, $last);
 }
コード例 #2
0
ファイル: Collection.php プロジェクト: stillat/collection
 /**
  * Get the last item from the collection.
  *
  * @param  callable|null $callback
  * @param  mixed         $default
  *
  * @return mixed
  */
 public function last(callable $callback = null, $default = null)
 {
     if (is_null($callback)) {
         return count($this->items) > 0 ? end($this->items) : value($default);
     }
     return Arr::last($this->items, $callback, $default);
 }