| 8 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.
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 = NestedArray::mergeDeep($link_options_1, $link_options_2);
Parameters
array ...: Arrays to merge.
bool $preserve_integer_keys: (optional) If given, integer keys will be preserved and merged instead of appended.
Return value
array The merged array.
See also
17 calls to NestedArray::mergeDeep()
- DatabaseStorageController::getFieldDefinitions in core/
lib/ Drupal/ Core/ Entity/ DatabaseStorageController.php - Implements \Drupal\Core\Entity\EntityStorageControllerInterface::getFieldDefinitions().
- editor_pre_render_format in core/
modules/ editor/ editor.module - Additional #pre_render callback for 'text_format' elements.
- EntityNormalizer::normalize in core/
modules/ hal/ lib/ Drupal/ hal/ Normalizer/ EntityNormalizer.php - Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
- field_views_data in core/
modules/ field/ field.views.inc - Implements hook_views_data().
- ModuleHandler::getHookInfo in core/
lib/ Drupal/ Core/ Extension/ ModuleHandler.php - Implements \Drupal\Core\Extension\ModuleHandlerInterface::getHookInfo().
File
- core/
lib/ Drupal/ Component/ Utility/ NestedArray.php, line 301 - Contains Drupal\Component\Utility\NestedArray.
Namespace
Drupal\Component\UtilityClass
- NestedArray
- Provides helpers to perform operations on nested arrays and array keys of variable depth.
Code
public static function mergeDeep() {
return self::mergeDeepArray(func_get_args());
}