3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function generate_upc_checkdigit($upc_code) { $odd_total = 0; $even_total = 0; for($i=0; $i<7; $i++) { if((($i+1)%2) == 0) { /* Sum even digits */ $even_total += $upc_code[$i]; } else { /* Sum odd digits */ $odd_total += $upc_code[$i]; } } $sum = (3 * $odd_total) + $even_total; /* Get the remainder MOD 10*/ $check_digit = $sum % 10; /* If the result is not zero, subtract the result from ten. */ return ($check_digit > 0) ? 10 - $check_digit : $check_digit; } echo generate_upc_checkdigit("123456"); ?>
Output for 7.1.0 - 7.2.0
Notice: Uninitialized string offset: 6 in /in/DCER7 on line 16 Warning: A non-numeric value encountered in /in/DCER7 on line 16 1
Output for 5.3.18 - 7.0.20
Notice: Uninitialized string offset: 6 in /in/DCER7 on line 16 1