将键值数组对象合并到Laravel PHP中的单个数组中

时间:2019-05-15 07:49:17

标签: php arrays json laravel

我有多个数据从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}]

0 个答案:

没有答案