You are here

public static function JsonBlueprintDenormalizer::arrayIsKeyed in Subrequests 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/JsonBlueprintDenormalizer.php \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer::arrayIsKeyed()
  2. 3.x src/Normalizer/JsonBlueprintDenormalizer.php \Drupal\subrequests\Normalizer\JsonBlueprintDenormalizer::arrayIsKeyed()

Check if an array is keyed.

Parameters

array $input: The input array to check.

Return value

bool True if the array is keyed.

2 calls to JsonBlueprintDenormalizer::arrayIsKeyed()
JsonBlueprintDenormalizer::supportsDenormalization in src/Normalizer/JsonBlueprintDenormalizer.php
Checks whether the given class is supported for denormalization by this normalizer.
JsonSubrequestDenormalizer::supportsDenormalization in src/Normalizer/JsonSubrequestDenormalizer.php
Checks whether the given class is supported for denormalization by this normalizer.

File

src/Normalizer/JsonBlueprintDenormalizer.php, line 89

Class

JsonBlueprintDenormalizer

Namespace

Drupal\subrequests\Normalizer

Code

public static function arrayIsKeyed(array $input) {
  $keys = array_keys($input);

  // If the array does not start at 0, it is not numeric.
  if ($keys[0] !== 0) {
    return TRUE;
  }

  // If there is a non-numeric key, the array is not numeric.
  $numeric_keys = array_filter($keys, 'is_numeric');
  if (count($keys) != count($numeric_keys)) {
    return TRUE;
  }

  // If the keys are not following the natural numbers sequence, then it is
  // not numeric.
  for ($index = 1; $index < count($keys); $index++) {
    if ($keys[$index] - $keys[$index - 1] !== 1) {
      return TRUE;
    }
  }
  return FALSE;
}