function AbstractCollection::merge
Parameters
CollectionInterface<T> ...$collections The collections to merge.:
Return value
CollectionInterface<T>
Throws
CollectionMismatchException if unable to merge any of the given collections or items within the given collections due to type mismatch errors.
Overrides CollectionInterface::merge
File
-
vendor/
ramsey/ collection/ src/ AbstractCollection.php, line 307
Class
- AbstractCollection
- This class provides a basic implementation of `CollectionInterface`, to minimize the effort required to implement this interface
Namespace
Ramsey\CollectionCode
public function merge(CollectionInterface ...$collections) : CollectionInterface {
$mergedCollection = clone $this;
foreach ($collections as $index => $collection) {
if (!$collection instanceof static) {
throw new CollectionMismatchException(sprintf('Collection with index %d must be of type %s', $index, static::class));
}
// When using generics (Collection.php, Set.php, etc),
// we also need to make sure that the internal types match each other
if ($this->getUniformType($collection) !== $this->getUniformType($this)) {
throw new CollectionMismatchException(sprintf('Collection items in collection with index %d must be of type %s', $index, $this->getType()));
}
foreach ($collection as $key => $value) {
if (is_int($key)) {
$mergedCollection[] = $value;
}
else {
$mergedCollection[$key] = $value;
}
}
}
return $mergedCollection;
}