You are here

public static function NestedArray::unsetValue in Blazy 7

Unsets a value in a nested array with variable depth.

Parameters

array $array: A reference to the array to modify.

array $parents: An array of parent keys, starting with the outermost key and including the key to be unset.

bool $key_existed: (optional) If given, an already defined variable that is altered by reference.

See also

NestedArray::setValue()

NestedArray::getValue()

File

src/Utility/NestedArray.php, line 95

Class

NestedArray
Provides helpers to perform operations on nested arrays, kidnapped from D8.

Namespace

Drupal\blazy\Utility

Code

public static function unsetValue(array &$array, array $parents, &$key_existed = NULL) {
  $unset_key = array_pop($parents);
  $ref =& self::getValue($array, $parents, $key_existed);
  if ($key_existed && is_array($ref) && (isset($ref[$unset_key]) || array_key_exists($unset_key, $ref))) {
    $key_existed = TRUE;
    unset($ref[$unset_key]);
  }
  else {
    $key_existed = FALSE;
  }
}