note 85409 modified in function.array-merge-recursive by thiago
| From: | thiago@php.net | Date: | Tue, 04 Nov 2008 23:52:23 +0000 |
| Subject: | note 85409 modified in function.array-merge-recursive by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146143@lists.php.net to get a copy of this message | ||
Needed some way to fuse two arrays together and found a function here (below from thomas) and
decided to update it even further to be a little more smart.
<?php
function my_array_merge ($arr,$ins)
{
if(is_array($arr))
{
if(is_array($ins)) foreach($ins as $k=>$v)
{
if(isset($arr[$k])&&is_array($v)&&is_array($arr[$k]))
{
$arr[$k] = my_array_merge($arr[$k],$v);
}
else $arr[$k] = $v;
}
}
elseif(!is_array($arr)&&(strlen($arr)==0||$arr==0))
{
$arr=$ins;
}
return($arr);
}
?>
--was--
Needed some way to fuse two arrays together and found a function here (below from thomas) and
decided to update it even further to be a little more smart.
<?php
function my_array_merge ($arr,$ins)
{
if(is_array($arr))
{
if(is_array($ins)) foreach($ins as $k=>$v)
{
if(isset($arr[$k])&&is_array($v)&&is_array($arr[$k]))
{
$arr[$k] = my_array_merge($arr[$k],$v);
}
else $arr[$k] = $v;
}
}
elseif(!is_array($arr)&&(strlen($arr)==0||$arr==0)
{
$arr=$ins;
}
return($arr);
}
?>
http://php.net/manual/en/function.array-merge-recursive.php