note 9037 deleted from function.array-merge-recursive by sniper

From: Date: Mon, 06 Oct 2003 22:59:23 +0000
Subject: note 9037 deleted from function.array-merge-recursive by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57940@lists.php.net to get a copy of this message
Note Submitter: kc@hireability.com ---- There seemed to be no built in function that would merge two arrays recursively and clobber any existing key/value pairs. Array_Merge() is not recursive, and array_merge_recursive seemed to give unsatisfactory results... it would append duplicate key/values. So here's a cross between array_merge and array_merge_recursive --------------------------------- function array_merge_clobber($a1,$a2) { if(!is_array($a1) || !is_array($a2)) return false; $newarray = $a1; while (list($key, $val) = each($a2)) { if (is_array($val) && is_array($newarray[$key])) { $newarray[$key] = array_merge_clobber($newarray[$key], $val); } else { $newarray[$key] = $val; } } return $newarray; } -------------------------------------

« previous php.notes (#57940) next »