$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,程式碼應該如何實現?在線等,求大神解救
補充一下:這裡類似是產生組合 每個組合下面可以有多個商品 商品數量可以定義例如 1-3個 2-3個