3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function GetLuhnCheckDigit($number) { $sum = 0; $alt = true; $digits = str_split($number); for ($i = count($digits) - 1; $i >= 0; $i--) { $curDigit = ($digits[$i] - 48); if ($alt) { $curDigit *= 2; if ($curDigit > 9) $curDigit -= 9; } $sum += $curDigit; $alt = false; } if (($sum % 10) == 0 ){ return 0; } echo abs($sum) . PHP_EOL; return (10 - (abs($sum) % 10)); } echo GetLuhnCheckDigit(1234567891234567891);
based on fjHZc
Output for 5.3.19 - 7.2.0
868 2