Skip to content

Commit

Permalink
closure can be passed into 'last' method, as in 'first' method
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Dm committed Jun 8, 2015
1 parent 403e04a commit 2c550d9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,19 @@ The `keys` method returns all of the collection's keys:
<a name="method-last"></a>
#### `last()` {#collection-method}

The `last` method returns the last item in the collection:
The `last` method returns the last element in the collection that passes a given truth test:

collect([1, 2, 3, 4, 5])->last();
collect([1, 2, 3, 4])->last(function ($key, $value) {
return $value < 3;
});

// 5
// 2

You may also call the `last` method with no arguments to get the last element in the collection. If the collection is empty, `null` is returned:

collect([1, 2, 3, 4])->last();

// 4

<a name="method-map"></a>
#### `map()` {#collection-method}
Expand Down

0 comments on commit 2c550d9

Please sign in to comment.