本文实例讲述了PHP实现通过Luhn算法校验信用卡卡号是否有效的方法。分享给大家供大家参考。具体实现方法如下:
$numbers = 49927398716 49927398717 1234567812345678 1234567812345670;
foreach (split(' ', $numbers) as $n)
echo $n is , luhnTest($n) ? 'valid' : 'not valid', '';
function luhnTest($num) {
$len = strlen($num);
for ($i = $len-1; $
1