Re: Re: [PATCH] New functions: array_replace[_recursive]

From: Date: Wed, 23 Jul 2008 13:44:00 +0000
Subject: Re: Re: [PATCH] New functions: array_replace[_recursive]
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-39226@lists.php.net to get a copy of this message
Hi Christian, ----- Original Message ----- From: "Christian Schneider" Sent: Wednesday, July 23, 2008 > Matt Wilmas wrote: > > array_replace() is like the + operator applied to arrays, except that it > > WILL overwrite ("replace") existing entries. > > Excuse my ignorance but what's the difference between > $array = array_replace($array1, $array2); > and > $array = $array2 + $array1; > apart from different order of the entries in the resulting array? The order of the entries is the only difference, I believe. :-) I think that's desirable however, and having the non-recursive version makes it match array_merge(), etc. As for bloat or something, there's virtually no extra code: only PHP_FUNCTION() and then in the wrapper function it just uses zend_hash_merge() just like the + operator, except with its "overwrite" param set to 1. > > array_replace_recursive() will do the same except that it becomes > > recursive only when both the destination and source entries are > > arrays, otherwise the new source entry still replaces any existing > > one. > > Hmm, generic enough to be included? What Lukas said. :-) > - Chris - Matt

« previous php.internals (#39226) next »