我有多个数据从PHP表单发布到laravel控制器。
[{"attribute":"4"},
{"variation":"4"},
{"price":null},
{"qty":"1"},
{"image":null},
{"variation":"kgg"},
{"price":"100"},
{"qty":"2"},
{"image":null},
{"attribute":"5"},
{"variation":"6"},
{"price":null},
{"qty":"3"},
{"image":null}]
我试图遍历每个键值,并尝试合并这些数组,但是它不起作用。
$data=[];
for ($i=0; $i < sizeof( $request->variations) ; $i++) {
foreach ($val[$i] as $key => $value) {
$data[]=
[ $key => $value ];
}
}
array_combine($data);
我想将此不同的对象组合成一个对象。
预期产量
[{"attribute":"4",
"variation":"4",
"price":null,
"qty":"1",
"image":null,
"variation":"kgg",
"price":"100",
"qty":"2",
"image":null,
"attribute":"5",
"variation":"6",
"price":null,
"qty":"3",
"image":null}]