Home  >  Q&A  >  body text

PHP generates two-dimensional arrays for multiple products and clears inventory

$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]

);

Generate an array according to the number of pieces until the inventory is cleared

Final result Similar to

[[{"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}]]

But the combination cannot have the same id. How should the code be implemented? Waiting online, asking God for help

CkleinCklein1523 days ago923

reply all(1)I'll reply

  • Cklein

    Cklein2020-09-10 11:34:24

    To add: This is similar to generating combinations. Each combination can have multiple products. The number of products can be defined, for example, 1-3 2-3

    reply
    0
  • Cancelreply