function _menu_views_array_merge_recursive in Menu Views 8.3
Same name and namespace in other branches
- 7.2 menu_views.module \_menu_views_array_merge_recursive()
array_merge_recursive does indeed merge arrays, but it converts values with duplicate keys to arrays rather than overwriting the value in the first array with the duplicate value in the second array, as array_merge does. I.e., with array_merge_recursive, this happens (documented behavior):
array_merge_recursive(array('key' => 'org value'), array('key' => 'new value')); => array('key' => array('org value', 'new value'));
array_merge_recursive_distinct does not change the datatypes of the values in the arrays. Matching keys' values in the second array overwrite those in the first array, as is the case with array_merge, i.e.:
array_merge_recursive_distinct(array('key' => 'org value'), array('key' => 'new value')); => array('key' => 'new value');
Parameters are passed by reference, though only for performance reasons. They're not altered by this function.
@author daniel@danielsmedegaardbuus.dk
Parameters
array $array1:
mixed $array2:
Return value
array
3 calls to _menu_views_array_merge_recursive()
- menu_views_node_prepare in ./
menu_views.module - Implements hook_node_prepare().
- _menu_views_form_submit in ./
menu_views.admin.inc - Submit handler for menu_edit_item form.
- _menu_views_get_item in ./
menu_views.module - Helper function to return the menu view array from a menu item array or form array.
File
- ./
menu_views.module, line 696 - Module to allow Views to be attached as menu items.
Code
function &_menu_views_array_merge_recursive(array &$array1, &$array2 = NULL) {
$merged = $array1;
if (is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($array2[$key])) {
$merged[$key] = isset($merged[$key]) && is_array($merged[$key]) ? _menu_views_array_merge_recursive($merged[$key], $array2[$key]) : $array2[$key];
}
else {
$merged[$key] = $val;
}
}
}
return $merged;
}