Search
 
SCRIPT & CODE EXAMPLE
 

PHP

luhn algorithm

<?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

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 :: database seeder laravel 
Php :: last item coma replace and php 
Php :: Unknown column type "double" requested. Any Doctrine type that you use has to be registered with DoctrineDBALTypesType::addType 
Php :: windows logged in user name in php 
Php :: Verzeichnis einlesen php 
Php :: faker image laravel 8 
Php :: Delete a single record in laravel 5 
Php :: php radians to degrees 
Php :: magento2 get full details of order collection 
Php :: laravel auth 
Php :: if exists in string count php 
Php :: php upload multiple files 
Php :: laravel eloquent bulk insert 
Php :: echo errors php 
Php :: php version command linux 
Php :: How do I change the URL of Add to cart in WooCommerce 
Php :: php strpos 
Php :: laravel modules 
Php :: group_concat mysql limit issue 
Php :: laravel make factory 
Php :: transaction laravel 
Php :: laravel make:middleware 
Php :: laravel collection collapse 
Php :: woocommerce get shipping classes 
Php :: php string literal 
Php :: naming the routes in laravel 
Php :: php injection 
Php :: Movie Name -inurl:(htm|html|php|pls|txt) intitle:index.of “last modified” (mp4|wma|aac|avi) 
Php :: laravel rule unique where 
Php :: laravel migration column types 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =