7.x bootstrap.inc drupal_array_merge_deep()

Merges multiple arrays, recursively, and returns the merged array.

This function is similar to PHP's array_merge_recursive() function, but it handles non-array values differently. When merging values that are not both arrays, the latter value replaces the former rather than merging with it.


$link_options_1 = array(
  'fragment' => 'x',
  'attributes' => array(
    'title' => t('X'),
    'class' => array(
$link_options_2 = array(
  'fragment' => 'y',
  'attributes' => array(
    'title' => t('Y'),
    'class' => array(

// This results in array('fragment' => array('x', 'y'), 'attributes' => array('title' => array(t('X'), t('Y')), 'class' => array('a', 'b', 'c', 'd'))).
$incorrect = array_merge_recursive($link_options_1, $link_options_2);

// This results in array('fragment' => 'y', 'attributes' => array('title' => t('Y'), 'class' => array('a', 'b', 'c', 'd'))).
$correct = drupal_array_merge_deep($link_options_1, $link_options_2);


...: Arrays to merge.

Return value

The merged array.

See also


3 calls to drupal_array_merge_deep()
BootstrapMiscTestCase::testMisc in modules/simpletest/tests/bootstrap.test
Test miscellaneous functions in bootstrap.inc.
drupal_add_js in includes/common.inc
Adds a JavaScript file, setting, or inline code to the page.
_drupal_file_scan_cache in includes/bootstrap.inc
Returns the current list of cached file system scan results.


includes/bootstrap.inc, line 2377
Functions that need to be loaded on every Drupal request.


function drupal_array_merge_deep() {
  $args = func_get_args();
  return drupal_array_merge_deep_array($args);


KeyboardCowboy’s picture