PHP generates two-dimensional arrays for multiple products and clears inventory
Cklein
Cklein 2020-09-10 11:32:25
0
1
851

$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

Cklein
Cklein

reply all (1)
Cklein

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

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!