diff --git a/src/Config.php b/src/Config.php index d55e9e9..d1a6c8b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -491,22 +491,9 @@ protected function _assertValidExtend($extendingSection, $extendedSection) protected function _arrayMergeRecursive($firstArray, $secondArray) { if (is_array($firstArray) && is_array($secondArray)) { - foreach ($secondArray as $key => $value) { - if (isset($firstArray[$key])) { - $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value); - } else { - if($key === 0) { - $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value)); - } else { - $firstArray[$key] = $value; - } - } - } - } else { - $firstArray = $secondArray; + return array_replace_recursive($firstArray, $secondArray); } - - return $firstArray; + return $secondArray; } /** diff --git a/src/Xml.php b/src/Xml.php index 26046cf..48dddac 100644 --- a/src/Xml.php +++ b/src/Xml.php @@ -292,4 +292,33 @@ protected function _toArray(\SimpleXMLElement $xmlObject) return $config; } + + /** + * Merge two arrays recursively, overwriting keys of the same name + * in $firstArray with the value in $secondArray. + * + * @param mixed $firstArray First array + * @param mixed $secondArray Second array to merge into first array + * @return array + */ + protected function _arrayMergeRecursive($firstArray, $secondArray) + { + if (is_array($firstArray) && is_array($secondArray)) { + foreach ($secondArray as $key => $value) { + if (isset($firstArray[$key])) { + $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value); + } else { + if($key === 0) { + $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value)); + } else { + $firstArray[$key] = $value; + } + } + } + } else { + $firstArray = $secondArray; + } + + return $firstArray; + } }