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.



Your result can be seen below.

Result of php executing





Full code of wisselgeld.php

  1. <?php
  2. $bedrag = floatval($argv[1]);
  3. $rest = 0;
  4. if (!$bedrag) {
  5.     exit("Geen wisselgeld");
  6. }
  7. define("GELDEENHEDEN", array(50, 20, 10, 5, 2, 1));
  8. $restbedrag = $bedrag;
  9.  
  10. foreach (GELDEENHEDEN as $valuta) {
  11.     if ($restbedrag >= $valuta) {
  12.         $aantal = floor($restbedrag / $valuta);
  13.         $restbedrag = fmod($restbedrag, $valuta);
  14.         echo "$aantal x $valuta euro" . PHP_EOL;
  15.     }
  16. }
  17.  
  18. $centen = $bedrag;
  19.  
  20. foreach (GELDEENHEDEN as $cent) {
  21.     if ($centen >= $cent / 100) {
  22.         $aantal = floor($centen / ($cent / 100));
  23.         $centen = $centen % $cent;
  24.         $centen = round(fmod($centen, ($cent / 100)));
  25.         echo "$aantal x $cent cent" . PHP_EOL;
  26.     }
  27. }
  28. ?>
File Description
  • wisselgeld
  • PHP Code
  • 12 Oct-2021
  • 708 Bytes
You can Share it: