Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

luhn algorithm credit card checker php

<?php
function is_valid_luhn($number) {
  settype($number, 'string');
  $sumTable = array(
    array(0,1,2,3,4,5,6,7,8,9),
    array(0,2,4,6,8,1,3,5,7,9));
  $sum = 0;
  $flip = 0;
  for ($i = strlen($number) - 1; $i >= 0; $i--) {
    $sum += $sumTable[$flip++ & 0x1][$number[$i]];
  }
  return $sum % 10 === 0;
}
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #luhn #algorithm #credit #card #checker #php
ADD COMMENT
Topic
Name
5+1 =