- <?php
- $num = "49927398716";
- $double = false;
- $ret = "";
- $ret .= ($double ? $num[$i] * 2 : $num[$i]);
- $double = !$double;
- }
- $sum = 0;
- $sum += $ret[$i];
- }
- echo "\$ret = $ret\n";
- echo "\$sum = $sum\n";
- if ($sum % 10) {
- echo "Invalid\n";
- } else {
- echo "Valid\n";
- }
Luhn algorithm
Posted by Admin on Sat 22nd Jan 2011 21:16
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.