Skip to content

Adding diffAssoc method to collection #3455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ For the remainder of this documentation, we'll discuss each method available on
[count](#method-count)
[diff](#method-diff)
[diffKeys](#method-diffkeys)
[diffAssoc](#method-diffassoc)
[each](#method-each)
[every](#method-every)
[except](#method-except)
Expand Down Expand Up @@ -309,6 +310,29 @@ The `diffKeys` method compares the collection against another collection or a pl
$diff->all();

// ['one' => 10, 'three' => 30, 'five' => 50]

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

The `diffAssoc` method compares the collection against another collection or a plain PHP `array` based on its keys and values. This method will return the key / value pairs in the original collection that are not present in the given collection:

$collection = collect([
       'color' => 'orange',
       'type' => 'fruit',
       'remain' => 6
  ]);

  $diff = $collection->diffAssoc([
      'color' => 'yellow',
       'type' => 'fruit',
       'remain' => 3,
       'used' => 6
 olor ]);

$diff->all();

  // ['color' => 'orange', 'remain' => 6]


<a name="method-each"></a>
#### `each()` {#collection-method}
Expand Down