*/
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();
<?php
/**
+ * Require our basic test case definition
+ */
+require_once dirname(__FILE__) . '/Autoload.php';
+
+/**
* @author Jan Schneider <jan@horde.org>
* @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()
$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)));
+ }
}