You are here

function clientside_validation_array_key_path in Clientside Validation 7

Search for a key in an array, returning a path to the entry.

Parameters

$needle: A key to look for.

$haystack: A keyed array.

$forbidden: A list of keys to ignore.

$path: The intermediate path. Internal use only.

$depth: The depth of the array to search.

$current_depth: The current depth searched. Internal use only.

Return value

The path to the parent of the first occurrence of the key, represented as an array where entries are consecutive keys.

1 call to clientside_validation_array_key_path()
clientside_validation_field_validation_clientside_validation_form_alter in clientside_validation_field_validation/clientside_validation_field_validation.module
Implements hook_clientside_validation_form_alter().

File

clientside_validation_field_validation/clientside_validation_field_validation.module, line 61
Add clientside validation support for Field Validation

Code

function clientside_validation_array_key_path($needle, $haystack, $forbidden = array(), $path = array(), $depth = 3, $current_depth = 0) {
  foreach ($haystack as $key => $val) {
    if (in_array($key, $forbidden)) {
      continue;
    }
    if (is_array($val) && $current_depth < $depth && is_array($sub = clientside_validation_array_key_path($needle, $val, $forbidden, array_merge($path, (array) $key), $depth, $current_depth + 1))) {
      return $sub;
    }
    elseif ($key === $needle) {
      return array_merge($path, (array) $key);
    }
  }
  return FALSE;
}