Skip to content

Instantly share code, notes, and snippets.

@hightemp
Created November 21, 2018 07:05
Show Gist options
  • Select an option

  • Save hightemp/84295c158079c4768c4ad8f4b8541470 to your computer and use it in GitHub Desktop.

Select an option

Save hightemp/84295c158079c4768c4ad8f4b8541470 to your computer and use it in GitHub Desktop.
<?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