3v4l.org

run code in 300+ PHP versions simultaneously
<?php function validate_EAN13Barcode($barcode) { // check to see if barcode is 13 digits long if (!preg_match("/^[0-9]{13}$/", $barcode)) { return false; } $digits = $barcode; // 1. Add the values of the digits in the // even-numbered positions: 2, 4, 6, etc. $even_sum = $digits[1] + $digits[3] + $digits[5] + $digits[7] + $digits[9] + $digits[11]; // 2. Multiply this result by 3. $even_sum_three = $even_sum * 3; // 3. Add the values of the digits in the // odd-numbered positions: 1, 3, 5, etc. $odd_sum = $digits[0] + $digits[2] + $digits[4] + $digits[6] + $digits[8] + $digits[10]; // 4. Sum the results of steps 2 and 3. $total_sum = $even_sum_three + $odd_sum; // 5. The check character is the smallest number which, // when added to the result in step 4, produces a multiple of 10. $next_ten = (ceil($total_sum / 10)) * 10; $check_digit = $next_ten - $total_sum; // if the check digit and the last digit of the // barcode are OK return true; if ($check_digit == $digits[12]) { return true; } return false; } echo "ean valide : ".validate_EAN13Barcode(3001209537341)."";
Output for 8.3.0 - 8.3.6
Warning: Trying to access array offset on int in /in/eVRLA on line 14 Warning: Trying to access array offset on int in /in/eVRLA on line 14 Warning: Trying to access array offset on int in /in/eVRLA on line 14 Warning: Trying to access array offset on int in /in/eVRLA on line 15 Warning: Trying to access array offset on int in /in/eVRLA on line 15 Warning: Trying to access array offset on int in /in/eVRLA on line 15 Warning: Trying to access array offset on int in /in/eVRLA on line 22 Warning: Trying to access array offset on int in /in/eVRLA on line 22 Warning: Trying to access array offset on int in /in/eVRLA on line 22 Warning: Trying to access array offset on int in /in/eVRLA on line 23 Warning: Trying to access array offset on int in /in/eVRLA on line 23 Warning: Trying to access array offset on int in /in/eVRLA on line 23 Warning: Trying to access array offset on int in /in/eVRLA on line 35 ean valide : 1
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Warning: Trying to access array offset on value of type int in /in/eVRLA on line 14 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 14 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 14 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 15 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 15 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 15 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 22 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 22 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 22 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 23 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 23 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 23 Warning: Trying to access array offset on value of type int in /in/eVRLA on line 35 ean valide : 1
Output for 7.4.0 - 7.4.33
Notice: Trying to access array offset on value of type int in /in/eVRLA on line 14 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 14 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 14 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 15 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 15 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 15 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 22 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 22 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 22 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 23 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 23 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 23 Notice: Trying to access array offset on value of type int in /in/eVRLA on line 35 ean valide : 1
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
ean valide : 1

preferences:
286.14 ms | 404 KiB | 422 Q