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

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