【发布时间】:2020-08-19 20:08:57
【问题描述】:
我有一个数组 $cart 结果像
array:5 [▼
188 => array:17 [▼
"user_id" => ""
"product_id" => "188"
"qty" => "2"
"date" => "03-05-2020"
"product_type" => "rear type"
"custom_color_title" => ""
"custom_color_price" => ""
"bolt_title" => ""
"bolt_price" => ""
"hub_center_rings_title" => ""
"hub_center_rings_price" => ""
"wheel_spacers_title" => ""
"wheel_spacers_price" => ""
"tire_pressure_title" => ""
"tire_pressure_price" => ""
"product_price" => 1890
"product_size" => ""
]
176 => array:17 [▼
"user_id" => ""
"product_id" => "176"
"qty" => "2"
"date" => "03-05-2020"
"product_type" => "wheel type"
"custom_color_title" => ""
"custom_color_price" => ""
"bolt_title" => ""
"bolt_price" => ""
"hub_center_rings_title" => ""
"hub_center_rings_price" => ""
"wheel_spacers_title" => ""
"wheel_spacers_price" => ""
"tire_pressure_title" => ""
"tire_pressure_price" => ""
"product_price" => 1680
"product_size" => ""
]
224 => array:17 [▶]
]
如何从这个数组更新 user_id 值并插入数据库?,数组 id 产品值的索引值所以我很困惑如何更新这个数组。
【问题讨论】:
-
您想用数组的索引更新
user_id的值吗?例如:如果索引是 176 那么 user_id:"176"? -
@AlwaysSunny 没有从会话值获取的用户 ID
-
所以假设会话中的用户 ID 为 100,那么数组中的所有 user_id 值将是 100 对吗?
-
@AlwaysSunny 是的
-
您是否尝试过编写一些代码?您要问的似乎可以通过遍历数组的内容来完成。