Search code examples
phparray-merge

What does $array2 += $array1 do?


I've seen the following often lately and I'm wondering what it does? I can't seem to find it in the PHP manual.

 $arr1 = array('key' => 'value1');
 $arr2 = array('key' => 'value2');
 $arr1 += $arr2;

Is it similar to an array_merge?

I know what the following does, but I don't understand what it does when working with an array:

 $var1 = 1;
 $var2 = 2;
 $var1 += $var2;
 echo $var1; // 3

Solution

  • The + operation between two arrays acts like a UNION.