PHP: find 2 or more numbers from a list of N numbers that can add up towards a given ammount

Posted by Splash on Stack Overflow See other posts from Stack Overflow or by Splash
Published on 2010-04-19T13:19:53Z Indexed on 2010/04/19 13:23 UTC
Read the original article Hit count: 218

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about sum