Search
 
SCRIPT & CODE EXAMPLE
 

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;
}
Comment

luhn algorithm credit card checker php

function validateLuhn(string $number): bool
{
    $sum = 0;
    $flag = 0;

    for ($i = strlen($number) - 1; $i >= 0; $i--) {
        $add = $flag++ & 1 ? $number[$i] * 2 : $number[$i];
        $sum += $add > 9 ? $add - 9 : $add;
    }

    return $sum % 10 === 0;
}
Comment

PREVIOUS NEXT
Code Example
Php :: Laravel Adding Cookie Consent 
Php :: create role spatie 
Php :: php call constant in class 
Php :: login form using php pdo 
Php :: php curl empty response 
Php :: {{count laravel 
Php :: echo in console command laravel 
Php :: mysql extension php enable 
Php :: worpdress pods taxonomy get custom field 
Php :: ?? Null Coalescing Operator PHP 
Php :: db seed in controller 
Php :: laravel blade components 
Php :: eloquent batch insert 
Php :: wp rest api acf fields 
Php :: laravel faker values 
Php :: aws sdk php 
Php :: how to create singleton laravel 
Php :: laravel module package 
Php :: read pdf text php 
Php :: laravel 6 make http request 
Php :: php contain 
Php :: woocommerce order status change 
Php :: laravel redirect action 
Php :: laravel 8 validation unique 2 columns 
Php :: how to download file from s3 bucket using php 
Php :: login page in php 
Php :: php extract number from string without comma 
Php :: php <= 
Php :: laravel request input default value 
Php :: laravel belongstomany prevent duplicates attach 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =