- substr: documentation ( source)
<?php
function _generateChecksum($eanCodeWithoutChecksum) {
$key = 0;
$mult = array(1, 3);
for ($i = 0; $i < strlen($eanCodeWithoutChecksum); $i++)
$key += substr($eanCodeWithoutChecksum, $i, 1) * $mult[$i % 2];
$key = 10 - ( $key % 10 );
if ($key == 10)
$key = 0;
return $key;
}
echo _generateChecksum(205240000003);