我的數(shù)據(jù)如下: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到每個數(shù)據(jù)數(shù)組中,例如: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截屏我的數(shù)據(jù)庫如下所示:代碼目前剛剛獲得我的專欄,還cart_data需要添加專欄。id$items2 = CartStorage::where('user_id', $user->id)->get();$items = [];foreach($items2 as $item){ $items[] = json_decode($item['cart_data']); }
1 回答

函數(shù)式編程
TA貢獻1807條經(jīng)驗 獲得超9個贊
可以通過創(chuàng)建一個 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 關(guān)注
- 175 瀏覽
添加回答
舉報
0/150
提交
取消