note 102859 added to function.array-replace-recursive
| From: | marcovtwout at hotmail dot com | Date: | Thu, 10 Mar 2011 14:30:26 +0000 |
| Subject: | note 102859 added to function.array-replace-recursive | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177741@lists.php.net to get a copy of this message | ||
If you want to use array_replace_recursive() on just two arrays in PHP <5.3, you can use this
simple function:
<?php
if (!function_exists('array_replace_recursive'))
{
function array_replace_recursive($a,$b)
{
foreach($b as $k=>$v)
{
if(is_array($v) && isset($a[$k]) && is_array($a[$k]))
$a[$k]=array_replace_recursive($a[$k],$v);
else
$a[$k]=$v;
}
return $a;
}
}
?>
Adapted from: http://www.yiiframework.com/doc/api/1.1/CMap/#mergeArray-detail
----
Server IP: 69.147.83.197
Probable Submitter: 80.101.112.45
----
Manual Page -- http://www.php.net/manual/en/function.array-replace-recursive.php
Edit -- https://master.php.net/note/edit/102859
Del: integrated -- https://master.php.net/note/delete/102859/integrated
Del: useless -- https://master.php.net/note/delete/102859/useless
Del: bad code -- https://master.php.net/note/delete/102859/bad+code
Del: spam -- https://master.php.net/note/delete/102859/spam
Del: non-english -- https://master.php.net/note/delete/102859/non-english
Del: in docs -- https://master.php.net/note/delete/102859/in+docs
Del: other reasons-- https://master.php.net/note/delete/102859
Reject -- https://master.php.net/note/reject/102859
Search -- https://master.php.net/manage/user-notes.php