public static function ArrayUtils::merge in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-stdlib/src/ArrayUtils.php \Zend\Stdlib\ArrayUtils::merge()
Merge two arrays together.
If an integer key exists in both arrays and preserveNumericKeys is false, the value from the second array will be appended to the first array. If both values are arrays, they are merged together, else the value of the second array overwrites the one of the first array.
Parameters
array $a:
array $b:
bool $preserveNumericKeys:
Return value
array
File
- vendor/
zendframework/ zend-stdlib/ src/ ArrayUtils.php, line 269
Class
- ArrayUtils
- Utility class for testing and manipulation of PHP arrays.
Namespace
Zend\StdlibCode
public static function merge(array $a, array $b, $preserveNumericKeys = false) {
foreach ($b as $key => $value) {
if ($value instanceof MergeReplaceKeyInterface) {
$a[$key] = $value
->getData();
}
elseif (isset($a[$key]) || array_key_exists($key, $a)) {
if ($value instanceof MergeRemoveKey) {
unset($a[$key]);
}
elseif (!$preserveNumericKeys && is_int($key)) {
$a[] = $value;
}
elseif (is_array($value) && is_array($a[$key])) {
$a[$key] = static::merge($a[$key], $value, $preserveNumericKeys);
}
else {
$a[$key] = $value;
}
}
else {
if (!$value instanceof MergeRemoveKey) {
$a[$key] = $value;
}
}
}
return $a;
}