[snip] it is a special case of the knapsack problem - the "subset sum" problem. You'll need to be aware that it's of exponential complexity. So make sure your lists of possible values don't get big. Anyway, here's my answer: [/snip] Thanks to all who responded, some very cool solutions and some more insight to the problem ("subset sum" as Robin mentions above) has given me the wheels that I need to solve the issue at hand. I wanted to point out something here while we are discussing this; there are tons of algorithms out there for solutions to problems such as these and we sometimes as developers (instead of mathematicians or logicians) fail to look for these when trying to solve the problem. My problem in this case was that I knew that there was an algorithm I just could not recall what it was. I managed to get close (knapsack problem) and the solutions provided by several of you were elegant and work well. There is another ongoing thread about OOP in PHP4 that has approached holy war status. I fear that some are overlooking solutions to problems that already have been solved. Things such as interfaces and design patterns exist because they are solutions to problems just as identifying the right problem here leads to a solution (the algorithm). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php