PHP: find 2 or more numbers from a list of N numbers that can add up towards a given ammount
- by Splash
Hi Guys,
I am trying to create a little php script that can make my life a bit easier.
Basically, I am going to have 21 text fields on a page where I am going to input 20 different numbers. In the last field I will enter a number let's call it the TOTAL AMMOUNT. All I want the script to do is to point out which numbers from the 20 fields added up will come up to TOTAL AMMOUNT.
Example:
field1= 25.23
field2= 34.45
field3= 56.67
field4= 63.54
field5= 87.54
....
field20= 4.2
Total Ammount= 81.90
Output: field1+fields3=81.90
Some of the fields might have 0 as value because sometimes I only need to enter 5-15 fields and the maximum will be 20.
If someone can help me out with the php code for this, will be greatly appreciated.