3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $ean = '1888440212609'; $code = substr($ean, 0, -1); $sequence_ean8 = array(3, 1); $sequence_ean13 = array(1, 3); $sums = 0; foreach(str_split($code) as $n => $digit) { if (strlen($code)==7){ $sums += $digit * $sequence_ean8[$n % 2]; } elseif (strlen($code)==12){ $sums += $digit * $sequence_ean13[$n % 2]; } else { echo "code length invalid"; } } $checksum = 10 - $sums % 10; if($checksum == 10){ $checksum = 0; } var_dump($code . $checksum === $ean);
Output for 5.0.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
bool(false)
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: str_split() in /in/hBWIL on line 10
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: str_split() in /in/hBWIL on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: str_split() in /in/hBWIL on line 10