PHP array grouping/conditionals is it possible?
I have a bit of an issue that I dug myself into. I have a list of items that have a field of what type of boxes they will fit in.
For example:
item | boxtype | Quantity
-------------------------------
item1 | A-10,C-20 | 3
item2 | C-10,D-20 | 2
The letter in the boxtype-column is the box type, the number that follows is how m开发者_高级运维any of the item can fit in it.
What I am trying to figure out how to use the least amount of boxes. I originally just divided the quantity by the letter number, if it was under 1 I used that box.
But on cases like the above, where i would use Box A for item1, on item2 I would have to use C. It would be better to use box C for both items since all of both items would fit.
Of course this is just a simplied version of the issue, if needed I could elaborate with more defined example. I was just wondering could I do all the sorting with arrays?
Thanks for any point in the right direction
EDIT - adding this array, from this array, is there an easy way test for conditions of the letters to determine which box type should be used?
Array
(
[AC] => Array
(
[A] => 0.75
[C] => 0.15
)
[CD] => Array
(
[C] => 0.2
[D] => 0.1
)
)
Sounds like a 1D/linear bin packing problem. I don't see what it has to do with a particular language (PHP) or feature (arrays). For those, please come up with a more concrete example (e.g.: How do I sort this array in PHP? array(blah => blah)
). For the former, do not specify a language at all, focus on the algorithm.
精彩评论