Skip to content

Commit

Permalink
[8.x] Update the docs to reflect the merge of reduceWithKeys into the…
Browse files Browse the repository at this point in the history
… existing reduce method (#6743)

* add reduceWithKeys to collections available methods

* Update collections.md

* update docs to reflect the merged reduceWithKeys into the existing reduce method

* remove the link

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
mokhosh and taylorotwell committed Jan 15, 2021
1 parent 589b321 commit b24b6bb
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions collections.md
Expand Up @@ -164,7 +164,6 @@ For the majority of the remaining collection documentation, we'll discuss each m
[put](#method-put)
[random](#method-random)
[reduce](#method-reduce)
[reduceWithKeys](#method-reducewithkeys)
[reject](#method-reject)
[replace](#method-replace)
[replaceRecursive](#method-replacerecursive)
Expand Down Expand Up @@ -1706,10 +1705,7 @@ The value for `$carry` on the first iteration is `null`; however, you may specif

// 10

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

The `reduceWithKeys` method reduces an associative collection to a single value, passing the result of previous iterations along with each key / value pair to the given callback:
The `reduce` method also passes array keys in associative collections to the given callback:

$collection = collect([
'usd' => 1400,
Expand All @@ -1725,7 +1721,7 @@ The `reduceWithKeys` method reduces an associative collection to a single value,

$collection->reduceWithKeys(function ($carry, $value, $key) use ($ratio) {
return $carry + ($value * $ratio[$key]);
}, 0);
});

// 4264

Expand Down

0 comments on commit b24b6bb

Please sign in to comment.