首页 >社区问答列表 >php 多个商品生成二维数组 把库存清空掉

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

  • Cklein
  • Cklein    2020-09-10 11:34:241楼

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

    +0添加回复

  • 回复