Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
titleCDV kód ellenőrzése
linenumberstrue
collapsetrue
public function isCdvCorrect()
{
    return $this->calculateCdv() == $this->cdv;
}

public function calculateCdv()
{
    $sum = 0;
    $j = 1;
    $valueAsString = (string) $this->value;
    for ($i = $this->getValueLength() - 1; $i > -1; $i--)
    {
        if ($j % 2 != 0)
        {
            $result = $valueAsString[$i] * 2;
        }
        else
        {
            $result = $valueAsString[$i];
        }

        foreach(str_split($result) as $digit)
        {
            $sum += $digit;
        }

        $j++;
    }
    return $sum % 10;
}

...