public static function NestedArray::mergeDeepArray

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

This function is equivalent to NestedArray::mergeDeep(), except the input arrays are passed as a single array parameter rather than a variable parameter list.

The following are equivalent:

The following are also equivalent:

See also

NestedArray::mergeDeep()

10 calls to NestedArray::mergeDeepArray()
CKEditorPluginManager::getEnabledPlugins in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php
Determines which plug-ins are enabled.
Config::merge in drupal/core/lib/Drupal/Core/Config/Config.php
Merges data into a configuration object.
Config::setOverriddenData in drupal/core/lib/Drupal/Core/Config/Config.php
Sets the current data for this configuration object.
ConfigContext::setOverrides in drupal/core/lib/Drupal/Core/Config/Context/ConfigContext.php
Implements \Drupal\Core\Config\Context\ContextInterface::setOverride().
drupal_merge_js_settings in drupal/core/includes/common.inc
Merges an array of settings arrays into a single settings array.

... See full list

File

drupal/core/lib/Drupal/Component/Utility/NestedArray.php, line 322
Contains Drupal\Component\Utility\NestedArray.

Class

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

Namespace

Drupal\Component\Utility

Code

public static function mergeDeepArray(array $arrays, $preserve_integer_keys = FALSE) {
  $result = array();
  foreach ($arrays as $array) {
    foreach ($array as $key => $value) {

      // Renumber integer keys as array_merge_recursive() does unless
      // $preserve_integer_keys is set to TRUE. Note that PHP automatically
      // converts array keys that are integer strings (e.g., '1') to integers.
      if (is_integer($key) && !$preserve_integer_keys) {
        $result[] = $value;
      }
      elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
        $result[$key] = self::mergeDeepArray(array(
          $result[$key],
          $value,
        ), $preserve_integer_keys);
      }
      else {
        $result[$key] = $value;
      }
    }
  }
  return $result;
}