From: Jan Schneider Date: Mon, 3 Jan 2011 11:56:30 +0000 (+0100) Subject: Use array_replace_recursive() if available. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5fff3c366c74a5c05ab15b4e1c8ddf15e517a0b7;p=horde.git Use array_replace_recursive() if available. --- diff --git a/framework/Util/lib/Horde/Array.php b/framework/Util/lib/Horde/Array.php index ecdb753ec..32aa358f6 100644 --- a/framework/Util/lib/Horde/Array.php +++ b/framework/Util/lib/Horde/Array.php @@ -213,6 +213,10 @@ class Horde_Array */ static public function array_merge_recursive_overwrite(array $a1, array $a2) { + if (function_exists('array_replace_recursive')) { + return array_replace_recursive($a1, $a2); + } + foreach ($a2 as $key => $val) { if (!isset($a1[$key])) { $a1[$key] = array(); diff --git a/framework/Util/test/Horde/Util/ArrayTest.php b/framework/Util/test/Horde/Util/ArrayTest.php index 4205d16da..3ac74fae8 100644 --- a/framework/Util/test/Horde/Util/ArrayTest.php +++ b/framework/Util/test/Horde/Util/ArrayTest.php @@ -1,12 +1,16 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @category Horde * @package Util * @subpackage UnitTests */ - class Horde_Util_ArrayTest extends PHPUnit_Framework_TestCase { public function setUp() @@ -49,4 +53,22 @@ class Horde_Util_ArrayTest extends PHPUnit_Framework_TestCase $this->array ); } + + public function testArrayMergeRecursive() + { + $this->assertEquals( + array('one' => 1, + 'two' => array('two/one' => 1, + 'two/two' => 22), + 'three' => 33, + 'four' => 4), + Horde_Array::array_merge_recursive_overwrite( + array('one' => 1, + 'two' => array('two/one' => 1, + 'two/two' => 2), + 'three' => 3), + array('two' => array('two/two' => 22), + 'three' => 33, + 'four' => 4))); + } }