如果$ a和$ b是数组,$ a + $ b的结果是什么?

OM *_*ity 1 php arrays

可能重复:
PHP中的数组+运算符?

如果$a$b都是数组,结果是$a + $b什么?

el.*_*ado 10

http://www.php.net/manual/en/language.operators.array.php

Union of $a and $b.
Run Code Online (Sandbox Code Playgroud)

+运算符将右手数组中剩余键的元素附加到左手,而重复键不会被覆盖.


cee*_*yoz 6

<?php

$a = array(1, 2, 3);
$b = array(4, 5, 6);
$c = $a + $b;

print_r($c);
Run Code Online (Sandbox Code Playgroud)

为我的结果:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
Run Code Online (Sandbox Code Playgroud)

但:

<?php

$a = array('a' => 1, 'b' => 2, 'c' => 3);
$b = array('d' => 4, 'e' => 5, 'f' => 6);
$c = $a + $b;

print_r($c);
Run Code Online (Sandbox Code Playgroud)

结果是:

Array
(
    [a] => 1
    [b] => 2
    [c] => 3
    [d] => 4
    [e] => 5
    [f] => 6
)
Run Code Online (Sandbox Code Playgroud)

因此,这里的答案似乎取决于数组的键控方式.