Fixes #11275: Added possibility of unset or force replace former value in ArrayHelper::merge()

This commit is contained in:
Robert Korulczyk
2016-08-03 21:49:49 +02:00
committed by Alexander Makarov
parent 0ac161b69d
commit 993f2aef28
6 changed files with 268 additions and 15 deletions

View File

@ -107,6 +107,8 @@ class BaseArrayHelper
* type and are having the same key.
* For integer-keyed elements, the elements from the latter array will
* be appended to the former array.
* You can use [[UnsetArrayValue]] object to unset value from previous array or
* [[ReplaceArrayValue]] to force replace former value instead of recursive merging.
* @param array $a array to be merged to
* @param array $b array to be merged from. You can specify additional
* arrays via third argument, fourth argument etc.
@ -119,7 +121,11 @@ class BaseArrayHelper
while (!empty($args)) {
$next = array_shift($args);
foreach ($next as $k => $v) {
if (is_int($k)) {
if ($v instanceof UnsetArrayValue) {
unset($res[$k]);
} elseif ($v instanceof ReplaceArrayValue) {
$res[$k] = $v->value;
} elseif (is_int($k)) {
if (isset($res[$k])) {
$res[] = $v;
} else {