Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractCollection.php

function AbstractCollection::diff

Parameters

CollectionInterface<T> $other The collection to check for divergent: items.

Return value

CollectionInterface<T>

Throws

CollectionMismatchException if the compared collections are of differing types.

Overrides CollectionInterface::diff

File

vendor/ramsey/collection/src/AbstractCollection.php, line 260

Class

AbstractCollection
This class provides a basic implementation of `CollectionInterface`, to minimize the effort required to implement this interface

Namespace

Ramsey\Collection

Code

public function diff(CollectionInterface $other) : CollectionInterface {
    $this->compareCollectionTypes($other);
    $diffAtoB = array_udiff($this->data, $other->toArray(), $this->getComparator());
    $diffBtoA = array_udiff($other->toArray(), $this->data, $this->getComparator());
    
    /** @var array<array-key, T> $diff */
    $diff = array_merge($diffAtoB, $diffBtoA);
    $collection = clone $this;
    $collection->data = $diff;
    return $collection;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal