Skip to content

Commit d036931

Browse files
Update docs for pop() and shift() (#7205)
* Update docs for pop() and shift() to include option to pass integer to retrieve multiple items * Update collections.md * Update collections.md Co-authored-by: Taylor Otwell <[email protected]>
1 parent e37def3 commit d036931

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

collections.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,18 @@ The `pop` method removes and returns the last item from the collection:
16051605

16061606
// [1, 2, 3, 4]
16071607

1608+
You may pass an integer to the `pop` method to remove and return multiple items from the end of a collection:
1609+
1610+
$collection = collect([1, 2, 3, 4, 5]);
1611+
1612+
$collection->pop(3);
1613+
1614+
// collect([5, 4, 3])
1615+
1616+
$collection->all();
1617+
1618+
// [1, 2]
1619+
16081620
<a name="method-prepend"></a>
16091621
#### `prepend()` {#collection-method}
16101622

@@ -1846,6 +1858,18 @@ The `shift` method removes and returns the first item from the collection:
18461858

18471859
// [2, 3, 4, 5]
18481860

1861+
You may pass an integer to the `shift` method to remove and return multiple items from the beginning of a collection:
1862+
1863+
$collection = collect([1, 2, 3, 4, 5]);
1864+
1865+
$collection->shift(3);
1866+
1867+
// collect([1, 2, 3])
1868+
1869+
$collection->all();
1870+
1871+
// [4, 5]
1872+
18491873
<a name="method-shuffle"></a>
18501874
#### `shuffle()` {#collection-method}
18511875

0 commit comments

Comments
 (0)