function 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.

Example:

$link_options_1 = array(
  'fragment' => 'x',
  'attributes' => array(
    'title' => t('X'),
    'class' => array(
      'a',
      'b',
    ),
  ),
);
$link_options_2 = array(
  'fragment' => 'y',
  'attributes' => array(
    'title' => t('Y'),
    'class' => array(
      'c',
      'd',
    ),
  ),
);

// 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);

Parameters

...: Arrays to merge.

Return value

The merged array.

See also

drupal_array_merge_deep_array()

3 calls to drupal_array_merge_deep()
field_views_data in drupal/core/modules/field/field.views.inc
Implements hook_views_data().
MiscUnitTest::testMisc in drupal/core/modules/system/lib/Drupal/system/Tests/Bootstrap/MiscUnitTest.php
Tests miscellaneous functions in bootstrap.inc.
WebTestBase::drupalPostAJAX in drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
Execute an Ajax submission.

File

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

Code

function drupal_array_merge_deep() {
  return drupal_array_merge_deep_array(func_get_args());
}