if $a and $b are bothe arrays the what would be the result of $a+$b?
Possible Duplicate:
+ operator for array in PHP?
If $a
and $b
are both arrays, what is the result of $a + $b
?
http://www.php.net/manual/en/language.operators.array.php
Union of $a and $b.
The + operator appends elements of remaining keys from the right handed array to the left handed, whereas duplicated keys are NOT overwritten.
<?php
$a = array(1, 2, 3);
$b = array(4, 5, 6);
$c = $a + $b;
print_r($c);
results in this for me:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
BUT:
<?php
$a = array('a' => 1, 'b' => 2, 'c' => 3);
$b = array('d' => 4, 'e' => 5, 'f' => 6);
$c = $a + $b;
print_r($c);
results in:
Array
(
[a] => 1
[b] => 2
[c] => 3
[d] => 4
[e] => 5
[f] => 6
)
So it would appear that the answer here depends on how your arrays are keyed.
我的测试
$ar1 = array('1', '2');
$ar2 = array('3', '4');
$test = $ar1 + $ar2;
print_r($test);
Array
(
[0] => 1
[1] => 2
)
链接地址: http://www.djcxy.com/p/58936.html
上一篇: 在PHP中的任何位置插入数组中的新项目