/** * Removes all of this collection's elements that are also contained in the specified collection (optional operation). * @param CollectionInterface $collection */ public function removeAll(CollectionInterface $collection) { $changed = false; if ($this->size() > $collection->size()) { $iterator = $collection->iterator(); while ($iterator->hasNext()) { $element = $iterator->next(); if ($this->contains($element)) { $this->remove($element); $changed = true; } } } else { $iterator = $this->iterator(); while ($iterator->hasNext()) { $element = $iterator->next(); if ($collection->contains($element)) { $iterator->remove(); $changed = true; } } } return $changed; }
/** * Removes from this list all of its elements that * are contained in the specified collection * @param CollectionInterface $collection * @return void */ public function removeAll(CollectionInterface $collection) { $this->array = array_values(array_diff($this->array, $collection->toArray())); }