Skip to content

Instantly share code, notes, and snippets.

@TorbenKoehn
Created July 7, 2016 15:32
Show Gist options
  • Save TorbenKoehn/53ab27b0e0157a0332b52dd8c4ba0500 to your computer and use it in GitHub Desktop.
Save TorbenKoehn/53ab27b0e0157a0332b52dd8c4ba0500 to your computer and use it in GitHub Desktop.
<?php
class MyCollection
{
//Iterator/ArrayAccess/Countable stuff...
public overload -(array $other)
{
return new self(array_diff($this->items, $other));
}
}
$col = new MyCollection(['a' => 1, 'b' => 2, 'c' => 3]);
$diff = $col - array_flip(['a', 'c']);
var_dump($col); // MyCollection(['b' => 2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment