亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 添加額外數據到數組

Laravel 添加額外數據到數組

PHP
慕森卡 2023-07-08 20:40:05
我的數據如下: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;

}


查看完整回答
反對 回復 2023-07-08
  • 1 回答
  • 0 關注
  • 164 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號