You are here

protected static function YamlFormArrayHelper::getKey in YAML Form 8

Get next or prev(ious) array key.

Parameters

array $array: An array.

string $key: A array key.

string $direction: The direction of the key to retrieve.

Return value

string|null The next or prev(ious) array key or NULL if no key is found.

See also

http://stackoverflow.com/questions/6407795/get-the-next-array-item-using...

2 calls to YamlFormArrayHelper::getKey()
YamlFormArrayHelper::getNextKey in src/Utility/YamlFormArrayHelper.php
Get the next key in an array.
YamlFormArrayHelper::getPreviousKey in src/Utility/YamlFormArrayHelper.php
Get the prev(ious) key in an array.

File

src/Utility/YamlFormArrayHelper.php, line 161

Class

YamlFormArrayHelper
Provides helper to operate on arrays.

Namespace

Drupal\yamlform\Utility

Code

protected static function getKey(array $array, $key, $direction) {
  $array_keys = array_keys($array);
  $array_key = reset($array_keys);
  do {
    if ($array_key == $key) {
      return $direction($array_keys);
    }
  } while ($array_key = next($array_keys));
  return NULL;
}