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

Breadcrumb

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

function Assert::uniqueValues

Does non strict comparisons on the items, so ['3', 3] will not pass the assertion.

Parameters

array $values:

string $message:

Throws

InvalidArgumentException

File

vendor/webmozart/assert/src/Assert.php, line 751

Class

Assert
Efficient assertions to validate the input/output of your methods.

Namespace

Webmozart\Assert

Code

public static function uniqueValues(array $values, $message = '') {
    $allValues = \count($values);
    $uniqueValues = \count(\array_unique($values));
    if ($allValues !== $uniqueValues) {
        $difference = $allValues - $uniqueValues;
        static::reportInvalidArgument(\sprintf($message ?: 'Expected an array of unique values, but %s of them %s duplicated', $difference, 1 === $difference ? 'is' : 'are'));
    }
}

API Navigation

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