note 72370 added to function.array-merge
| From: | asteddy at tin dot it | Date: | Tue, 16 Jan 2007 15:51:47 +0000 |
| Subject: | note 72370 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121800@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 217.133.35.137
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- https://master.php.net/note/edit/72370
Del: integrated -- https://master.php.net/note/delete/72370/integrated
Del: useless -- https://master.php.net/note/delete/72370/useless
Del: bad code -- https://master.php.net/note/delete/72370/bad+code
Del: spam -- https://master.php.net/note/delete/72370/spam
Del: non-english -- https://master.php.net/note/delete/72370/non-english
Del: in docs -- https://master.php.net/note/delete/72370/in+docs
Del: other reasons-- https://master.php.net/note/delete/72370
Reject -- https://master.php.net/note/reject/72370
Search -- https://master.php.net/manage/user-notes.php