Created
November 21, 2018 07:05
-
-
Save hightemp/84295c158079c4768c4ad8f4b8541470 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $check_digit = function($inn, $coefficients) { | |
| $n = 0; | |
| foreach ($coefficients as $i => $k) { | |
| $n += $k * (int) $inn{$i}; | |
| } | |
| return $n % 11 % 10; | |
| }; | |
| switch ($inn_length) { | |
| case 10: | |
| $n10 = $check_digit($inn, [2, 4, 10, 3, 5, 9, 4, 6, 8]); | |
| if ($n10 === (int) $inn{9}) { | |
| $status = true; | |
| } | |
| break; | |
| case 12: | |
| $n11 = $check_digit($inn, [7, 2, 4, 10, 3, 5, 9, 4, 6, 8]); | |
| $n12 = $check_digit($inn, [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8]); | |
| if (($n11 === (int) $inn{10}) && ($n12 === (int) $inn{11})) { | |
| $status = true; | |
| } | |
| break; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment