我在php中有2个数组(我使用echo json_encode())来显示输出:
echo json_encode($ arr);
[{'a':1}]
和echo json_encode($ arr2);
[{'something':1},{'something2':2}]
当我做$ arr [] = $ arr2;它输出这个
[{'a':1}[{'something':1},{'something2':2}]]
我想要的是
[{'a':1},{'something':1},{'something2':2}]
答案 0 :(得分:0)
只需使用array_merge
:
$res = array_merge($arr, $arr2);
答案 1 :(得分:0)
$result = array_merge($arr, $arr2);
json_encode($result);
//Output:
//[{'a':1},{'something':1},{'something2':2}]