Find Quantity

I have a problem and I need a php function to solve it.

I have a table like this (it can have multiple any number of rows):

——————————————–
Unit Price | Product Name | Quantity
——————————————–
10.366 test –
25 test –
6.4 test –
———————————————
TOTAL PRICE : 1665

Now I want to see what are the quantities for the 3 products above so if we do QT1*Price1 + QT2*Price2 + QT3*Price3 = 1665

I need a function that except how much products,prices,total price and max quantity.
And then the function will do all combinations so it find the correct quantities combination, or it returns false if no results.

For example if I give to the function this :
How much products = 3
Max quantity = 2
prices = 5,7,2
total prices = 266
The programm will do like this:
1 1 1 is (1*5 + 1*7 + 1*2) = 266 YES ? returns the 1,1,1 ELSE continue
1 1 2 same..
1 2 1 same…
1 2 2 same…
2 1 1 same…
2 1 2 same…
2 2 1 same…
2 2 2 same…

Leave a Reply

Your email address will not be published. Required fields are marked *