Sha256: 26dbc31323264750830d2633fcb5f273543131feead9af61e6976a06348ce4d7

Contents?: true

Size: 572 Bytes

Versions: 275

Compression:

Stored size: 572 Bytes

Contents

<?php

function isValid($candidate)
{
    $sanitizedCandidate = str_replace(" ", "", $candidate) ;

    if (strlen($sanitizedCandidate) <= 1 || !ctype_digit($sanitizedCandidate)) {
        return false ;
    }

    $reversseCandidate = strrev($sanitizedCandidate) ;
    $sum = 0 ;

    for ($i = 1; $i < strlen($reversseCandidate); $i+=2) {
        $digit = 2 * intval($reversseCandidate{$i}) ;

        if ($digit > 9) {
            $digit -= 9 ;
        }

        $sum += $digit ;
        $sum += intval($reversseCandidate{$i-1}) ;
    }

    return $sum % 10 == 0 ;
}

Version data entries

275 entries across 275 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/php/exercises/luhn/example.php
trackler-2.2.1.179 tracks/php/exercises/luhn/example.php
trackler-2.2.1.178 tracks/php/exercises/luhn/example.php
trackler-2.2.1.177 tracks/php/exercises/luhn/example.php
trackler-2.2.1.176 tracks/php/exercises/luhn/example.php
trackler-2.2.1.175 tracks/php/exercises/luhn/example.php
trackler-2.2.1.174 tracks/php/exercises/luhn/example.php
trackler-2.2.1.173 tracks/php/exercises/luhn/example.php
trackler-2.2.1.172 tracks/php/exercises/luhn/example.php
trackler-2.2.1.171 tracks/php/exercises/luhn/example.php
trackler-2.2.1.170 tracks/php/exercises/luhn/example.php
trackler-2.2.1.169 tracks/php/exercises/luhn/example.php
trackler-2.2.1.167 tracks/php/exercises/luhn/example.php
trackler-2.2.1.166 tracks/php/exercises/luhn/example.php
trackler-2.2.1.165 tracks/php/exercises/luhn/example.php
trackler-2.2.1.164 tracks/php/exercises/luhn/example.php
trackler-2.2.1.163 tracks/php/exercises/luhn/example.php
trackler-2.2.1.162 tracks/php/exercises/luhn/example.php
trackler-2.2.1.161 tracks/php/exercises/luhn/example.php
trackler-2.2.1.160 tracks/php/exercises/luhn/example.php