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

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

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


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

Union of $a and $b.

+操作符将右手阵列中剩余键的元素附加到左手,而重复键不会被覆盖。


<?php

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

print_r($c);

结果在我这里:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)

但:

<?php

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

print_r($c);

结果是:

Array
(
    [a] => 1
    [b] => 2
    [c] => 3
    [d] => 4
    [e] => 5
    [f] => 6
)

所以看起来这里的答案取决于你的数组是如何被键入的。


我的测试

$ar1 = array('1', '2');
$ar2 = array('3', '4');
$test = $ar1 + $ar2;
print_r($test);

Array
(
    [0] => 1
    [1] => 2
)
链接地址: http://www.djcxy.com/p/58935.html

上一篇: if $a and $b are bothe arrays the what would be the result of $a+$b?

下一篇: PHP Error Setting on Local and Remote Apache Servers