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


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to