8.2.x NestedArray.php public static NestedArray::mergeDeep()
8.0.x NestedArray.php public static NestedArray::mergeDeep()
8.1.x NestedArray.php public static NestedArray::mergeDeep()
8.3.x NestedArray.php public static NestedArray::mergeDeep()

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('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 = NestedArray::mergeDeep($link_options_1, $link_options_2);


array ...: Arrays to merge.

Return value

array The merged array.

See also


30 calls to NestedArray::mergeDeep()
ArgumentPluginBase::calculateDependencies in core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
Calculates dependencies for the configured plugin.
BlockBase::setConfiguration in core/lib/Drupal/Core/Block/BlockBase.php
Sets the configuration for this plugin instance.
ClientFactory::fromOptions in core/lib/Drupal/Core/Http/ClientFactory.php
Constructs a new client object from some configuration.
ConfigEntityBase::getDependencies in core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
Gets the configuration dependencies.
ConfigEntityDependency::__construct in core/lib/Drupal/Core/Config/Entity/ConfigEntityDependency.php
Constructs the configuration entity dependency from the entity values.

... See full list


core/lib/Drupal/Component/Utility/NestedArray.php, line 294


Provides helpers to perform operations on nested arrays and array keys of variable depth.




public static function mergeDeep() {
  return self::mergeDeepArray(func_get_args());