function NestedArray::mergeDeepArray
Same name in other branches
- 8.9.x core/lib/Drupal/Component/Utility/NestedArray.php \Drupal\Component\Utility\NestedArray::mergeDeepArray()
- 10 core/lib/Drupal/Component/Utility/NestedArray.php \Drupal\Component\Utility\NestedArray::mergeDeepArray()
- 11.x core/lib/Drupal/Component/Utility/NestedArray.php \Drupal\Component\Utility\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:
- NestedArray::mergeDeep($a, $b);
- NestedArray::mergeDeepArray(array($a, $b));
The following are also equivalent:
- call_user_func_array('NestedArray::mergeDeep', $arrays_to_merge);
- NestedArray::mergeDeepArray($arrays_to_merge);
Parameters
array $arrays: An arrays of arrays to merge.
bool $preserve_integer_keys: (optional) If given, integer keys will be preserved and merged instead of appended. Defaults to FALSE.
Return value
array The merged array.
See also
NestedArray::mergeDeep()
28 calls to NestedArray::mergeDeepArray()
- AssetResolver::getJsAssets in core/
lib/ Drupal/ Core/ Asset/ AssetResolver.php - Returns the JavaScript assets for the current response's libraries.
- AssetResolver::getJsSettingsAssets in core/
lib/ Drupal/ Core/ Asset/ AssetResolver.php - Returns the JavaScript settings assets for this response's libraries.
- BubbleableMetadata::mergeAttachments in core/
lib/ Drupal/ Core/ Render/ BubbleableMetadata.php - Merges two attachments arrays (which live under the '#attached' key).
- CKEditor4to5UpgradeCompletenessTest::testButtons in core/
modules/ ckeditor5/ tests/ src/ Kernel/ CKEditor4to5UpgradeCompletenessTest.php - Tests that all CKEditor 4 buttons in core have an upgrade path.
- CKEditor5PluginManager::getCKEditor5PluginConfig in core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5PluginManager.php - Gets the configuration for the CKEditor 5 plugins enabled in this editor.
File
-
core/
lib/ Drupal/ Component/ Utility/ NestedArray.php, line 324
Class
- NestedArray
- Provides helpers to perform operations on nested arrays and array keys of variable depth.
Namespace
Drupal\Component\UtilityCode
public static function mergeDeepArray(array $arrays, $preserve_integer_keys = FALSE) {
$result = [];
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_int($key) && !$preserve_integer_keys) {
$result[] = $value;
}
elseif (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
$result[$key] = self::mergeDeepArray([
$result[$key],
$value,
], $preserve_integer_keys);
}
else {
$result[$key] = $value;
}
}
}
return $result;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.