<?php
$a = ['php', 'j' => 'java', 'p' => 'python'];
$b = ['go', 'j' => 'javascript', 'r' => 'ruby'];
var_dump(array_merge($a, $b));
var_dump($a + $b);
array_merge:如果key为string,merge后后面数组会覆盖前面数组,如果key为int,键名会以连续方式重新索引。
array(5) {
[0] =>
string(3) "php"
'j' =>
string(10) "javascript"
'p' =>
string(6) "python"
[1] =>
string(2) "go"
'r' =>
string(4) "ruby"
}
+:如果key相等,相加后前面数组的值会覆盖后面数组的值
array(4) {
[0] =>
string(3) "php"
'j' =>
string(4) "java"
'p' =>
string(6) "python"
'r' =>
string(4) "ruby"
}
网友评论