You are here

public static function Inspector::assertStrictArray in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Component/Assertion/Inspector.php \Drupal\Component\Assertion\Inspector::assertStrictArray()

Asserts that the array is strict.

What PHP calls arrays are more formally called maps in most other programming languages. A map is a datatype that associates values to keys. The term 'strict array' here refers to a 0-indexed array in the classic sense found in programming languages other than PHP.

Parameters

mixed $array: Variable to be examined.

Return value

bool TRUE if $traversable is a 0-indexed array.

See also

http://php.net/manual/language.types.array.php

1 call to Inspector::assertStrictArray()
InspectorTest::testAssertStrictArray in core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php
Tests asserting array is 0-indexed - the strict definition of array.

File

core/lib/Drupal/Component/Assertion/Inspector.php, line 150

Class

Inspector
Generic inspections for the assert() statement.

Namespace

Drupal\Component\Assertion

Code

public static function assertStrictArray($array) {
  if (!is_array($array)) {
    return FALSE;
  }
  $i = 0;
  foreach (array_keys($array) as $key) {
    if ($i !== $key) {
      return FALSE;
    }
    $i++;
  }
  return TRUE;
}