Skip to content

Commit b24b6bb

Browse files
mokhoshtaylorotwell
andauthoredJan 15, 2021
[8.x] Update the docs to reflect the merge of reduceWithKeys into the 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>
1 parent 589b321 commit b24b6bb

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed
 

‎collections.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ For the majority of the remaining collection documentation, we'll discuss each m
164164
[put](#method-put)
165165
[random](#method-random)
166166
[reduce](#method-reduce)
167-
[reduceWithKeys](#method-reducewithkeys)
168167
[reject](#method-reject)
169168
[replace](#method-replace)
170169
[replaceRecursive](#method-replacerecursive)
@@ -1706,10 +1705,7 @@ The value for `$carry` on the first iteration is `null`; however, you may specif
17061705

17071706
// 10
17081707

1709-
<a name="method-reducewithkeys"></a>
1710-
#### `reduceWithKeys()` {#collection-method}
1711-
1712-
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:
1708+
The `reduce` method also passes array keys in associative collections to the given callback:
17131709

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

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

17301726
// 4264
17311727

0 commit comments

Comments
 (0)