note 72370 deleted from function.array-merge by levim
| From: | levim@php.net | Date: | Mon, 24 Feb 2014 22:56:24 +0000 |
| Subject: | note 72370 deleted from function.array-merge by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198687@lists.php.net to get a copy of this message | ||
Note Submitter: asteddy at tin dot it
----
Sorry, I forgot to translate the the name of the function when it calls itself. Here is the correct
code:
<?
/*
IT KEEPS ALL VALUES OF $arr1 AND
ADDS ALL KEYS AND VALUES OF $arr2 THAT ARE NOT IN $arr1
*/
function array_merge_keys($arr1, $arr2) {
foreach($arr2 as $k=>$v) {
if (!array_key_exists($k, $arr1)) { //K DOESN'T EXISTS //
$arr1[$k]=$v;
}
else { // K EXISTS //
if (is_array($v)) { // K IS AN ARRAY //
$arr1[$k]=array_merge_keys($arr1[$k], $arr2[$k]);
}
}
}
return $arr1;
}
?>