首页  >  问答  >  正文

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,代码应该如何实现?在线等,求大神解救

CkleinCklein1522 天前920

全部回复(1)我来回复

  • Cklein

    Cklein2020-09-10 11:34:24

    补充一下:这里类似是生成组合  每个组合下面可以有多个商品 商品数量可以定义例如 1-3个 2-3个

    回复
    0
  • 取消回复