php 多個商品產生二維數組 把庫存清空掉
Cklein
Cklein 2020-09-10 11:32:25
0
1
932

$allPackGoods = array(

   ['id'=>1,'stock'=>14,'num'=>6],

   ['id' =>2,'stock'=>20,'num'=>6],

   ['id'=>3,'stock'=>20,'num'=> ;6],

   ['id'=>4,'stock'=>18,'num'=>6],

   ['id'=>5 ,'stock'=>54,'num'=>6]

);

依照件數去產生陣列直到把庫存都清空掉

最終結果類似

[[{"id":1,"stock":8,"num":6,"use":6},{"id":2,"stock":14,"num ":6,"use":6},{"id":3,"stock":14,"num":6,"use":6}],[{"id":1,"stock": 2,"num":6,"use":6},{"id":2,"stock":2,"num":6,"use":6},{"id":4,"stock ":12,"num":6,"use":6}]]

但組合裡面不能有相同的id,程式碼應該如何實現?在線等,求大神解救

Cklein
Cklein

全部回覆(1)
Cklein

補充一下:這裡類似是產生組合  每個組合下面可以有多個商品 商品數量可以定義例如 1-3個 2-3個

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板