модуль — проверить контрольную цифру 11 (мод 11), используя переполнение стека

Как проверить номер NHS, используя контрольную цифру 11 (мод 11), используя PHP.

После долгих поисков в интернете, пытаясь найти функцию, которую я могу использовать для проверки номера контрольной цифры 11 (мод 11), я не смог ее найти, поэтому в итоге я разработал ее и поделился ею здесь. Я надеюсь, что кто-то мой найдет это полезным.

1

Решение

Код с комментариями:

###### Check Digit 11 Modulus
function mod11($nhs_no){
//Get Last Number
$checkDigit = (int)substr($nhs_no, -1);
//Get Remaining Numbers
$numbers = substr($nhs_no, 0, -1);
// Sort Numbers Into an Array
$numbers_array = str_split($numbers);
//Define the base for the weights
$base=2;
// Multiply the weights to the numbers
$numbers_array_reversed =  array_reverse($numbers_array);
foreach($numbers_array_reversed as $number){$multiplier[$number.'x'.$base]=(float)$number * $base;$base++;}
//Get the total sum
$sum =(float) array_sum($multiplier);
$modulus = 11;
// Divide the sum by check digit 11
$divider = (float)($sum / $modulus);
// Get the remainder
$remainder = (int)(($divider - (int)$divider)*$modulus);
// Check if the remainder is matching with the last check digit
$results = (int) ($modulus-$remainder);
// Return true or false
return ($results == $checkDigit ? true : false);
}
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector