Skip to content

Commit

Permalink
[1.x] Add multiply method to collection (#9731)
Browse files Browse the repository at this point in the history
* add `multiply` method to collection

* Update collections.md

* Update collections.md

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
milwad-dev and taylorotwell authored Jul 3, 2024
1 parent 2256340 commit 0599e7c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ For the majority of the remaining collection documentation, we'll discuss each m
[mergeRecursive](#method-mergerecursive)
[min](#method-min)
[mode](#method-mode)
[multiply](#method-multiply)
[nth](#method-nth)
[only](#method-only)
[pad](#method-pad)
Expand Down Expand Up @@ -1689,6 +1690,29 @@ The `mode` method returns the [mode value](https://en.wikipedia.org/wiki/Mode_(s

// [1, 2]

<a name="method-multiply"></a>
#### `multiply()` {.collection-method}

The `multiply` method creates the specified number of copies of all items in the collection:

```php
$users = collect([
['name' => 'User #1', 'email' => 'user1@example.com'],
['name' => 'User #2', 'email' => 'user2@example.com'],
])->multiply(3);

/*
[
['name' => 'User #1', 'email' => 'user1@example.com'],
['name' => 'User #2', 'email' => 'user2@example.com'],
['name' => 'User #1', 'email' => 'user1@example.com'],
['name' => 'User #2', 'email' => 'user2@example.com'],
['name' => 'User #1', 'email' => 'user1@example.com'],
['name' => 'User #2', 'email' => 'user2@example.com'],
]
*/
```

<a name="method-nth"></a>
#### `nth()` {.collection-method}

Expand Down

0 comments on commit 0599e7c

Please sign in to comment.