public static function ArrayHelper::getNestedValue in Helper 7
2 calls to ArrayHelper::getNestedValue()
File
- lib/
ArrayHelper.php, line 5
Class
Code
public static function getNestedValue($item, array $parents, &$key_exists = NULL) {
$ref = $item;
foreach ($parents as $parent) {
if (is_array($ref) && array_key_exists($parent, $ref)) {
$ref =& $ref[$parent];
}
elseif (is_object($ref) && property_exists($ref, $parent)) {
$ref = $ref->{$parent};
}
elseif (is_object($ref) && method_exists($ref, '__get') && $ref
->__get($parent) !== NULL) {
// Support objects that override the __get magic method.
// This also doesn't support if $ref->$parent exists but is set to NULL.
$ref = $ref->{$parent};
}
else {
$key_exists = FALSE;
return NULL;
}
}
$key_exists = TRUE;
return $ref;
}