On this page
function drupal_array_merge_deep_array
drupal_array_merge_deep_array($arrays)
Merges multiple arrays, recursively, and returns the merged array.
This function is equivalent to drupal_array_merge_deep(), except the input arrays are passed as a single array parameter rather than a variable parameter list.
The following are equivalent:
- drupal_array_merge_deep($a, $b);
- drupal_array_merge_deep_array(array($a, $b));
The following are also equivalent:
- call_user_func_array('drupal_array_merge_deep', $arrays_to_merge);
- drupal_array_merge_deep_array($arrays_to_merge);
See also
File
- includes/bootstrap.inc, line 2384
- Functions that need to be loaded on every Drupal request.
Code
function drupal_array_merge_deep_array($arrays) {
$result = array();
foreach ($arrays as $array) {
foreach ($array as $key => $value) {
// Renumber integer keys as array_merge_recursive() does. Note that PHP
// automatically converts array keys that are integer strings (e.g., '1')
// to integers.
if (is_integer($key)) {
$result[] = $value;
}
// Recurse when both values are arrays.
elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
$result[$key] = drupal_array_merge_deep_array(array($result[$key], $value));
}
// Otherwise, use the latter value, overriding any previous value.
else {
$result[$key] = $value;
}
}
}
return $result;
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_array_merge_deep_array/7.x