- Output for git.master, git.master_jit, rfc.property-hooks
- <? $upc = "5901234123457"; //valid //"889296852094"; //"5901244123457"; //invalid //"889295852094"; echo isValidBarcode($upc) ? 1 : 0; function isValidBarcode($barcode) { $barcode = trim($barcode); $bcLen = strlen($barcode); //If value is not numeric, it is not valid. if (!is_numeric($barcode) && ($bcLen == 12 || $bcLen == 13)) return false; //set empty variables $even_sum = $odd_sum = 0; preg_match_all('/(\w)(\w)/',$barcode,$oddEven); $even_sum = array_sum($oddEven[1]); // If you have an odd number of chars in the barcode, this regex will not account for the last char. // If you have an even number of chars, you will still need to pop the last char off manually. if($bcLen % 2 === 0) array_pop($oddEven[2]); $odd_sum = array_sum($oddEven[2]); //Multiply even_sum by 3, and then add odd_sum to it. $total_sum = $even_sum * 3 + $odd_sum; //get highest multiple of 10 of total_sum. $next_ten = ceil($total_sum / 10) * 10; //Subtract highest multiple of 10 from total_sum to get check_digit. $check_digit = $next_ten - $total_sum; //if check_digit is equal to the last digit in the barcode, it is valid. return $check_digit == substr($barcode, $bcLen-1); }
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
- 2020-03-21 RFC: Is_Literal - declined
- 2020-12-04 Enumerations - included in PHP 8.1
- 2018-06-15 Typed Properties v2 - implemented in PHP 7.4
- 2016-08-12 Object typehint - included in PHP 7.2
- 2016-08-14 Arrow functions - withdrawn
- 2016-05-29 array_change_keys() - withdrawn
- 2016-04-19 Lexical scope support for anonymous classes - suspended
- 2016-04-17 Functional Interfaces - declined
- 2016-03-16 Typed Properties - superseded in favor of Typed Properties 2.0
- 2015-08-27 Callable Prototypes - declined
- 2015-05-01 Short Closures - declined / withdrawn in favor of Arrow Functions
- 2015-02-18 Scalar type hints v5 - included in PHP 7
- 2015-02-14 Union Types - declined
- 2013-09-22 Anonymous classes - included in PHP 7