我在php中有两个数组喜欢这个:
$a = [ 1 => [ 0 => 10, 1 => 1 ] ] and $b = [ 1 => [ 0 => 15, 1 => 3 ] ]
我必须将这两个数组联合起来,结果数组应该是这样的:
$r = [ 1 => [ 0 => 10, 1 => 1 ], 1 => [ 0 => 15, 1 => 3 ] ]
请告诉我如何实现这一目标..
提前致谢!!
答案 0 :(得分:1)
你不能给出相同的数组索引....索引是唯一的
$r[] = $a;
$r[] = $b;
所以你的数组将是
$r = [ [0]=>[1 => [ 0 => 10, 1 => 1 ]], [1] =>[1 => [ 0 => 15, 1 => 3 ] ]]
答案 1 :(得分:0)
您不能拥有具有相同密钥的阵列。
如果要合并两个数组的值,请使用array_merge:
smallest