Skip to content

Instantly share code, notes, and snippets.

@stuartloxton
Created August 17, 2010 13:21
Show Gist options
  • Save stuartloxton/529901 to your computer and use it in GitHub Desktop.
Save stuartloxton/529901 to your computer and use it in GitHub Desktop.
<?php
function luhnCheck($number) {
$digits = str_split($number);
for( $i = (count($digits) - 2); $i >= 0; $i -= 2 ) {
$digits[$i] *= 2;
}
$digits = str_split(implode($digits));
return (array_sum($digits) % 10) === 0;
}
// returns true if a number passes the luhn (mod 10) check.
// (http://en.wikipedia.org/wiki/Luhn_algorithm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment