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.38 tracks/php/exercises/luhn/example.php
trackler-2.2.1.37 tracks/php/exercises/luhn/example.php
trackler-2.2.1.36 tracks/php/exercises/luhn/example.php
trackler-2.2.1.35 tracks/php/exercises/luhn/example.php
trackler-2.2.1.34 tracks/php/exercises/luhn/example.php
trackler-2.2.1.33 tracks/php/exercises/luhn/example.php
trackler-2.2.1.32 tracks/php/exercises/luhn/example.php
trackler-2.2.1.31 tracks/php/exercises/luhn/example.php
trackler-2.2.1.30 tracks/php/exercises/luhn/example.php
trackler-2.2.1.29 tracks/php/exercises/luhn/example.php
trackler-2.2.1.28 tracks/php/exercises/luhn/example.php
trackler-2.2.1.27 tracks/php/exercises/luhn/example.php
trackler-2.2.1.26 tracks/php/exercises/luhn/example.php
trackler-2.2.1.25 tracks/php/exercises/luhn/example.php
trackler-2.2.1.24 tracks/php/exercises/luhn/example.php
trackler-2.2.1.23 tracks/php/exercises/luhn/example.php
trackler-2.2.1.22 tracks/php/exercises/luhn/example.php
trackler-2.2.1.21 tracks/php/exercises/luhn/example.php
trackler-2.2.1.20 tracks/php/exercises/luhn/example.php
trackler-2.2.1.19 tracks/php/exercises/luhn/example.php