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
- $valuta = floatval($argv[1]);
- $rest = 0;
- if (!$valuta) {
- exit("Geen wisselgeld");
- }
- define("GELDEENHEDEN", array(50, 20, 10, 5, 2, 1));
- $restbedrag = $valuta;
- foreach (GELDEENHEDEN as $valuta) {
- if ($restbedrag >= $valuta) {
- $aantal = floor($restbedrag / $valuta);
- $restbedrag = $restbedrag % $valuta;
- echo "$aantal x $valuta euro" . PHP_EOL;
- }
- }
- $centen = $valuta;
- foreach (GELDEENHEDEN as $cent) {
- if ($centen >= $cent / 100) {
- $aantal = floor($centen / ($cent / 100));
- $centen = $centen % $cent;
- $centen = round(fmod($centen, ($cent / 100)));
- echo "$aantal x $cent cent" . PHP_EOL;
- }
- }
- ?>