I have a list of groups, which can vary in number, items in these groups may vary in number Are there.
Bonus: I also need all the combinations of not having every item in the group.
What I have seen and done, but it is necessary to know the number of groups to start with is.
To be more specific about what I am doing, I create a product with precise pricing based on product options. Here's an example list:
< Img src = "https://i.imgur.com/ELbO0.png" alt = "group / item example">
Then it will be as product generated:
UV coating , Volume 500, color 4: 0
UV coating, volume 500, color 4: 1
etc ...
Each of these groups has an ID, and each item has a Group_Item_ID Hence I can put them in an array:
$ selection [1] [...] // 1 = coating $ selection [2] [...] // 2 = quantity / / ... all the selected items in the group
Hopefully I have explained it well enough
Here is an example array for groups and their objects: / P>
array ([0] = & gt; array ([0] => 2 [1] => 3) [1] = & gt; array ([0] = 10] [1] => 11 [2] => 12) [2] => Array ([0] => 16 [1] => 17) [3] = & Gt; Hey ([0] => 19 [1] => 2))
Try it out:
function c ($ group, $ prefix = '') {$ result = array (); $ Group = array_shift ($ group); Foreign exchange ($ group $ selected) {if ($ group) {$ result = array_merge ($ result, c ($ group, $ prefix. $ Selected. ')); } And {$ result [] = $ prefix $ selected; }} The result of the return; }
Comments
Post a Comment