wisselgeld - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of wisselgeld.php
- <?php
- define("GELDEENHEDENEURO", ["50", "20", "10", "5", "2", "1"]);
- $input = $argv[1];
- $rest = (float)$input;
- echo "restant = " . $rest . PHP_EOL;
- if (!$input) {
- exit("Geen wisselgeld") . PHP_EOL;
- } else {
- foreach (GELDEENHEDENEURO as $valuta) {
- if ($rest >= $valuta) {
- $aantal_valuta = floor($rest / $valuta);
- $rest = fmod($rest, $valuta);
- echo $aantal_valuta . " x " . $valuta . " euro" . PHP_EOL;
- echo $rest . PHP_EOL;
- }
- }
- }
- define("GELDEENHEDENCENT", ["50", "20", "10", "5", "2", "1"]);
- $centen = round(0.50);
- $centen = round(0.20);
- $centen = round(0.10);
- $centen = round(0.05);
- $centen = round(0.02);
- $centen = round(0.01);
- echo "restant = " . $rest . PHP_EOL;
- $rest = $rest * 100;
- if ($rest >= 1) {
- foreach (GELDEENHEDENCENT as $centen) {
- $aantal_centen = floor($rest / $centen);
- $rest = fmod($rest, $centen);
- $centen = round($centen);
- if ($aantal_centen >= 0) {
- echo $aantal_centen . " x " . $centen . " cent" . PHP_EOL;
- }
- }
- }