debug - 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 debug.php

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <?php
  6.  function computeCheckDigit($identificationNumber) {
  7.      for ($i; $i <= strlen($identificationNumber); $i++) {
  8.          if ($i % 2 == 0) {
  9.              $sum += $identificationNumber{$i};
  10.          }
  11.      }
  12.  
  13.     $sum *= 3;
  14.  
  15.      for ($i; $i <= strlen($identificationNumber); $i++) {
  16.          if ($i % 2 != 0) {
  17.              $sum += $identificationNumber{$i};
  18.          }
  19.      }
  20.      
  21.      $array = str_split($sum);
  22.      $lastDigit = end($sum);
  23.      $result = 10 - $lastDigit;
  24.     
  25.      return $result;
  26.  
  27. }
  28. echo computeCheckDigit('39847');
  29. //expected 7
  30. ?>
  31.  
  32. </body>
  33. </html>
  34.  
File Description
  • debug
  • PHP Code
  • 08 Oct-2021
  • 640 Bytes
You can Share it: