# PHP Coins Change: Solve the coin change problem for a given amount

 Version License PHP version Categories coins-change 0.1 GNU General Publi... 5.0 Algorithms, PHP 5, Finances
Description

Author

This class can solve the coin change problem for a given amount.

It can take a given change amount and computes the smallest number of a given set of available coins to make up the change amount.

The class may consider an infinite number of coins of each value or just a limited number of coins of each one.

Innovation Award
 September 2014 Number 9Prize: One book of choice by Packt Vending machines usually need to give change for the amount the customer paid after subtracting the due amount for the goods the customer purchased. This class implements an algorithm to compute the number of coins to make up a given change amount, considering the number of coins available for different types of coin. Manuel Lemos
 Performance Level
Name: Classes: Michele Andreoli is available for providing paid consulting. Contact Michele Andreoli . 7 packages by Michele Andreoli Italy 38 540 18 in Italy 275 14 in Italy
Innovation award

Nominee: 4x

## Example

 ```      * @name index.php      * @version 0.1 updated 30-08-2014      * @license http://opensource.org/licenses/gpl-license-php GNU Public License      * @package CoinsChanger      */     require_once 'CoinsManager.class.php';            \$amount = 30;     \$coins = [50, 10, 5, 2, 1, 0.5];     \$limits = [1, 2, 1, 5, 3, 10];         //Coin change problem with FINITE coins supply     \$changerMngr = new CoinsManager(\$coins, \$limits);         //Get an array with coins     \$exchange = \$changerMngr->getChange(\$amount);     //Get an array with the amount for each denominations     \$groups = \$changerMngr->groupBy(\$exchange);         //Coin change problem with INFINITE coins supply     \$changerMngrInfinite = new CoinsManager(\$coins);         //Get an array with coins     \$exchangeInfinite = \$changerMngrInfinite->getChange(\$amount);     //Get an array with the amount for each denominations     \$groupsInfinite = \$changerMngrInfinite->groupBy(\$exchangeInfinite); ?>             Coins Changer Machine

Coins changer with finite coins supply

Change with:

No solutions

";             }             else {         ?>
\$group) {                     echo "
• " . \$key . "€ => " . \$group . "
• ";                 }             ?>

Coins changer with infinite coins supply

Change with:

No solutions

";             }             else {         ?>
\$group) {                     echo "
• " . \$key . "€ => " . \$group . "
• ";                 }             ?>
```

 Files
File Role Description
CoinsManager.class.php Class Main class for coin changer
index.php Example Example of use
output.html Output Output sample

For more information send a message to `info at phpclasses dot org`.