搜尋

首頁  >  問答  >  主體

php 多個商品產生二維數組 把庫存清空掉

$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,程式碼應該如何實現?在線等,求大神解救

CkleinCklein1536 天前935

全部回覆(1)我來回復

  • Cklein

    Cklein2020-09-10 11:34:24

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

    回覆
    0
  • 取消回覆