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