TestNew2 - 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 TestNew2.php
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- function computeCheckDigit($identificationNumber) {
- $sum = 0;
- for ($i = 0; $i <= strlen($identificationNumber); $i++) {
- if ($i % 2 == 0) {
- $sum += $identificationNumber[$i];
- }
- }
- $sum *= 3;
- for ($j = 0; $j <= strlen($identificationNumber); $j++) {
- if ($j % 2 != 0) {
- $sum += $identificationNumber[$j];
- }
- }
- $array = str_split($sum);
- $lastDigit = end($sum);
- $result = 10 - $lastDigit;
- return $result;
- }
- echo computeCheckDigit('39847');
- //expected 3
- ?>
- </body>
- </html>
File Description
- TestNew2
- PHP Code
- 08 Oct-2021
- 630 Bytes
You can Share it:
Latest PHP Pastes