Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class Luhn
{
public function luhn_check($number)
{
$number = preg_replace('/\D/', '', $number);
$number_length = strlen($number);
$eachSecond = $number_length % 2;
$total = 0;
for ($i = $number_length - 1; $i >= 0; $i--) {
$chislo = $number[$i];
if ($i % 2 == $eachSecond) {
$chislo *= 2;
if ($chislo > 9) {
$chislo -= 9;
}
}
$total += $chislo;
$total *= 9;
}
return $total;
}
public function valiCheck($total)
{
$rest = 0;
$rest = $total % 10;
if ($rest % 10 == 0) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.