SHARE
TWEET

Untitled

a guest Mar 26th, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function is_valid_luhn($number) {
  2.   settype($number, 'string');
  3.   $sumTable = array(
  4.     array(0,1,2,3,4,5,6,7,8,9),
  5.     array(0,2,4,6,8,1,3,5,7,9));
  6.   $sum = 0;
  7.   $flip = 0;
  8.   for ($i = strlen($number) - 1; $i >= 0; $i--) {
  9.     $sum += $sumTable[$flip++ & 0x1][$number[$i]];
  10.   }
  11.   return $sum % 10 === 0;
  12. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top