comparison core/lib/Drupal/Component/Utility/NestedArray.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
67 * @see NestedArray::unsetValue() 67 * @see NestedArray::unsetValue()
68 */ 68 */
69 public static function &getValue(array &$array, array $parents, &$key_exists = NULL) { 69 public static function &getValue(array &$array, array $parents, &$key_exists = NULL) {
70 $ref = &$array; 70 $ref = &$array;
71 foreach ($parents as $parent) { 71 foreach ($parents as $parent) {
72 if (is_array($ref) && array_key_exists($parent, $ref)) { 72 if (is_array($ref) && (isset($ref[$parent]) || array_key_exists($parent, $ref))) {
73 $ref = &$ref[$parent]; 73 $ref = &$ref[$parent];
74 } 74 }
75 else { 75 else {
76 $key_exists = FALSE; 76 $key_exists = FALSE;
77 $null = NULL; 77 $null = NULL;
217 * @see NestedArray::getValue() 217 * @see NestedArray::getValue()
218 */ 218 */
219 public static function unsetValue(array &$array, array $parents, &$key_existed = NULL) { 219 public static function unsetValue(array &$array, array $parents, &$key_existed = NULL) {
220 $unset_key = array_pop($parents); 220 $unset_key = array_pop($parents);
221 $ref = &self::getValue($array, $parents, $key_existed); 221 $ref = &self::getValue($array, $parents, $key_existed);
222 if ($key_existed && is_array($ref) && array_key_exists($unset_key, $ref)) { 222 if ($key_existed && is_array($ref) && (isset($ref[$unset_key]) || array_key_exists($unset_key, $ref))) {
223 $key_existed = TRUE; 223 $key_existed = TRUE;
224 unset($ref[$unset_key]); 224 unset($ref[$unset_key]);
225 } 225 }
226 else { 226 else {
227 $key_existed = FALSE; 227 $key_existed = FALSE;