PHP implementation of the Luhn algorithm. Commonly used in identificationnumbers, including IMEI and credit card numbers.
Unlike some implementations this one handles both odd and even number ofdigits.
<?php// Preferably autoload instead of using requirerequire'src/Luhn.php';useTdely\Luhn\Luhn;$original =82356937851;// Calculate check digitvar_dump(Luhn::checksum($original));// int(1)// Calculate and add check digit to number$checksum = Luhn::create($original);var_dump($checksum);// string(12) "823569378511"// Validate numbersvar_dump(Luhn::isValid($original));// bool(false)var_dump(Luhn::isValid($checksum));// bool(true)