Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/Config.php
Expand Up @@ -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;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions src/Xml.php
Expand Up @@ -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;
}
}

0 comments on commit d36a7f1

Please sign in to comment.