-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dac0f70
commit 9d8d25c
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,6 +334,29 @@ The `count` method returns the total number of items in the collection: | |
|
||
// 4 | ||
|
||
<a name="method-countBy"></a> | ||
#### `countBy()` {#collection-method} | ||
|
||
The `countBy` method counts the occurences of values in the collection. | ||
|
||
By default, it counts the occurrences of every element: | ||
|
||
$collection = collect([1, 2, 2, 2, 3]); | ||
|
||
$collection->countBy(); | ||
|
||
// collect([1 => 1, 2 => 3, 3 => 1]) | ||
|
||
It also accepts a callback: | ||
|
||
$collection = collect([ '[email protected]', '[email protected]', '[email protected]' ]); | ||
|
||
$collection->countBy(function ($email) { | ||
return substr(strrchr($email, "@"), 1); | ||
}); | ||
|
||
// collect([ 'gmail.com' => 2, 'yahoo.fr' => 1 ]) | ||
|
||
<a name="method-crossjoin"></a> | ||
#### `crossJoin()` {#collection-method} | ||
|
||
|