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
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- define("GELDEENHEDEN", ["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 (GELDEENHEDEN 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;
- }
- }
- }
- echo(round(0.50) . "<br>");
- echo(round(0.20) . "<br>");
- echo(round(0.10) . "<br>");
- echo(round(0.05) . "<br>");
- echo(round(0.02) . "<br>");
- echo(round(0.01));
- echo "restant = " . $rest . PHP_EOL;
- $rest = $rest * 100;
- if ($rest >= 1) {
- foreach (GELDEENHEDEN 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;
- }
- }
- }