[development] += on arrays

Karoly Negyesi karoly at negyesi.net
Tue Jan 17 15:52:09 UTC 2006


+= 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


More information about the development mailing list