3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function ean_checksum($eancode) { $result = false; if(strlen($eancode) == 13) { $check_code = substr($eancode, 12, 1); $eancode = substr($eancode, 0, 12); $oddsum=0; $evensum=0; $total=0; $eanvalue=$eancode; $finalean = strrev(substr($eanvalue,0,12)); for($i=0;$i<strlen($finalean);$i++) { if(($i % 2) == 0) { $oddsum += intval($finalean[$i]); } else { $evensum += intval($finalean[$i]); } } $total = ($oddsum * 3) + $evensum; $check = intval(10 - ceil($total % 10.0)) %10; if($check == $check_code) { $result = true; } } return $result; } $t = '4892503141771'; var_dump(ean_checksum($t));
based on D20vg
Output for 4.3.0 - 7.1.0
bool(true)