[development] += on arrays

Larry Garfield larry at garfieldtech.com
Wed Jan 18 01:12:38 UTC 2006


(Probable naivete on my part follows.)

So... array_merge($a, $b) favors $a, while $a += $b favors $b?  Wouldn't that 
mean that 

array_merge($a, $b) == $b += $a

Or am I just being dense? :-)

On Tuesday 17 January 2006 09:52, Karoly Negyesi wrote:
> += is not array_merge.
>
> array_merge overwrites keys that are the same while += does not overwrite.
> (now, that I read PHP source code, I know that $a += $a; for arrays is
> nicely optimized: the add function immediately returns and does iterate /
> copy etc the whole array needlessly.)
>
> In short: no, because
>
> >    $form['foo'] = array('a' => 'b', 'c' => 'd');
> >    $form['foo'] += array('a' => 'new b', 'e' => 'f');
>
> would result in array('a' => 'b', 'c' => 'd', 'e' => 'f');
>
> Regards
>
> NK

-- 
Larry Garfield			AIM: LOLG42
larry at garfieldtech.com		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson


More information about the development mailing list