我的数据如下:data: [,…] 0: {name: "Product One", price: "15000", quantity: 2, attributes: {attr: {name: "weight", value: "35"}},…} attributes: {attr: {name: "weight", value: "35"}} conditions: [{name: "blue", value: 0}, {name: "L", value: 0}] name: "Product One" price: "15000" quantity: 2我需要添加id到每个数据数组中,例如:data: [,…] 0: {name: "Product One", price: "15000", quantity: 2, attributes: {attr: {name: "weight", value: "35"}},…} attributes: {attr: {name: "weight", value: "35"}} conditions: [{name: "blue", value: 0}, {name: "L", value: 0}] name: "Product One" price: "15000" quantity: 2 id: 10 // added id截屏我的数据库如下所示:代码目前刚刚获得我的专栏,还cart_data需要添加专栏。id$items2 = CartStorage::where('user_id', $user->id)->get();$items = [];foreach($items2 as $item){ $items[] = json_decode($item['cart_data']); }
1 回答
函数式编程
TA贡献1807条经验 获得超9个赞
可以通过创建一个 var 并将其添加到那里,如下所示:
$items2 = CartStorage::where('user_id', $user->id)->get();
$items = [];
foreach($items2 as $item){
$decodedItems = json_decode($item['cart_data'], true);
$decodedItems['id'] = $item['id'];
$items[] = $decodedItems;
}
- 1 回答
- 0 关注
- 141 浏览
添加回答
举报
0/150
提交
取消