note 9037 modified in array_merge_recursive by ronabop

From: Date: Tue, 17 Oct 2000 06:03:05 +0000
Subject: note 9037 modified in array_merge_recursive by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-6552@lists.php.net to get a copy of this message
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; } ------------------------------------- http://www.php.net/manual/function.array-merge-recursive.php

« previous php.notes (#6552) next »