[limb-svn] r5984 - in 3.x/trunk/limb/core: src tests/cases
svn at limb-project.com
svn at limb-project.com
Mon Jun 11 13:16:13 MSD 2007
Author: pachanga
Date: 2007-06-11 13:16:12 +0400 (Mon, 11 Jun 2007)
New Revision: 5984
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5984
Modified:
3.x/trunk/limb/core/src/lmbArrayHelper.class.php
3.x/trunk/limb/core/tests/cases/lmbArrayHelperTest.class.php
Log:
-- lmbArrayHelper :: arrayMerge(..) now can accept many arguments
Modified: 3.x/trunk/limb/core/src/lmbArrayHelper.class.php
===================================================================
--- 3.x/trunk/limb/core/src/lmbArrayHelper.class.php 2007-06-09 13:33:06 UTC (rev 5983)
+++ 3.x/trunk/limb/core/src/lmbArrayHelper.class.php 2007-06-11 09:16:12 UTC (rev 5984)
@@ -1,18 +1,18 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
- */
-
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
/**
* class lmbArrayHelper.
*
* @package core
* @version $Id$
- */
+ */
class lmbArrayHelper
{
function map($map_array, $src_array, &$dest_array)
@@ -22,12 +22,21 @@
$dest_array[$dest] = $src_array[$src];
}
- function arrayMerge($a1, $a2)
+ function arrayMerge($a1, $a2)//we need at least two args and we specify them explicitly
{
+ $args = func_get_args();
+ $res = $a1;
+ for($i=1;$i<sizeof($args);$i++)
+ $res = self :: _arrayMerge($res, $args[$i]);
+ return $res;
+ }
+
+ function _arrayMerge($a1, $a2)
+ {
$n = $a1;
foreach($a2 as $k => $v)
if(is_array($v) && isset($n[$k]) && is_array($n[$k]))
- $n[$k] = lmbArrayHelper :: arrayMerge($n[$k], $v);
+ $n[$k] = self :: _arrayMerge($n[$k], $v);
else
$n[$k] = $v;
return $n;
Modified: 3.x/trunk/limb/core/tests/cases/lmbArrayHelperTest.class.php
===================================================================
--- 3.x/trunk/limb/core/tests/cases/lmbArrayHelperTest.class.php 2007-06-09 13:33:06 UTC (rev 5983)
+++ 3.x/trunk/limb/core/tests/cases/lmbArrayHelperTest.class.php 2007-06-11 09:16:12 UTC (rev 5984)
@@ -1,10 +1,10 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/core/src/lmbArrayHelper.class.php');
@@ -19,6 +19,17 @@
array('apple', 'nested' => array(2), 'b' => 1, 'a' => 1));
}
+ function testArrayMergeMany()
+ {
+ $a = array('orange', 'nested' => array(1), 'b' => 1);
+ $b = array('apple', 'nested' => array(2), 'a' => 1);
+ $c = array('banana', 'b' => 2);
+
+ $this->assertEqual(lmbArrayHelper :: arrayMerge($a, $b, $c),
+ array('banana', 'nested' => array(2), 'b' => 2, 'a' => 1));
+
+ }
+
function testMap()
{
$map = array('foo' => 'foo1', 'bar' => 'bar1');
More information about the limb-svn
mailing list