OP没有具体说明该联盟是按 值/strong>,还是通过key,而PHP则有,即合并价值和+
合并钥匙。 成果取决于阵列是否是指数化还是主要为和,这些阵列首先出现。
$a = [ a , b ];
$b = [ b , c ];
$c = [ a => A , b => B ];
$d = [ a => AA , c => C ];
Indexed array
见array_joint
。
By value using array_merge
array_merge($a, $b); // [0 => a , 1 => b , 2 => b , 3 => c ]
array_merge($b, $a); // [0 => b , 1 => c , 2 => a , 3 => b ]
merge by key using +
operator
见营运人
。
$a + $b; // [0 => a , 1 => b ]
$b + $a; // [0 => b , 1 => c ]
Keyed array
By value using array_merge
array_merge($c, $d); // [ a => AA , b => B , c => C ]
array_merge($d, $c); // [ a => A , c => C , b => B ]
merge by key using +
operator
$c + $d; // [ a => A , b => B , c => C ]
$d + $c; // [ a => AA , c => C , b => B ]