3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function ean_checksum($eancode) { if(strlen($eancode) != 12) { return '-1'; } $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; return $check; } $ean = '074436100720'; echo ean_checksum($ean);
based on V3iFh
Output for 4.3.0 - 7.1.0
8