3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function generateUpcCheckdigit($upc_code) { $odd_total = 0; $even_total = 0; for ($i = 1; $i <= strlen($upc_code); $i++) { //echo "Checking i=$i ({$upc_code[$i - 1]})...\n"; if ($i % 2 == 0) { //echo "even\n"; /* Sum even digits */ $even_total += $upc_code[$i - 1]; } else { //echo "odd\n"; /* Sum odd digits */ $odd_total += $upc_code[$i - 1]; } } $sum = (3 * $even_total) + $odd_total; //echo "Sum: $sum\n"; /* 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; } $coupons = [ [ 'signature' => 7685, 'description' => '10% off coupons', ], [ 'signature' => 7632, 'description' => '$15 off $50 coupons', ], ]; foreach ($coupons as $coupon) { echo "{$coupon['description']}:" . PHP_EOL; for ($i = 0; $i < 10; $i++) { $upc_code = '47000' . rand(0, 4) . rand(1000, 9999) . $coupon['signature']; echo $upc_code . generateUpcCheckdigit($upc_code) . PHP_EOL; } echo PHP_EOL; }
Output for 7.2.6
10% off coupons: 470001194676854 470000541776858 470002382876858 470004537376855 470002603576857 470004965176850 470002578076857 470004202376852 470003635776857 470003529376859 $15 off $50 coupons: 470001941076326 470000782776327 470000129576320 470004834776327 470001691876320 470001497276324 470004661876320 470003460176327 470001430676327 470000987676323
Output for 7.2.0
10% off coupons: 470002378776858 470001188676853 470004896176851 470004861176855 470003718076850 470003572776859 470001878576852 470001223976856 470001113076857 470003963676850 $15 off $50 coupons: 470004419876329 470000881076328 470003814976320 470001292376328 470003611876328 470002180976323 470001170176323 470001605276321 470002894776325 470004927676329
Output for 7.1.10
10% off coupons: 470000237076859 470002823276858 470000926376857 470001423376852 470004147776854 470004900276850 470002910276853 470003887376850 470002594076855 470003191776858 $15 off $50 coupons: 470003180676329 470003622976321 470000160076322 470001111176320 470002197676322 470003442276328 470000110676329 470000681476328 470004666176326 470004410676324
Output for 7.1.7
10% off coupons: 470000300776853 470002205476852 470002977076854 470002904876854 470004583376854 470003860176859 470003826676850 470003985276854 470002564676856 470003912276858 $15 off $50 coupons: 470002849576321 470002464176326 470003765476320 470001297576327 470002826376326 470002928076322 470003588076325 470003255576325 470000836676320 470004827576323
Output for 7.1.6
10% off coupons: 470002414276854 470002813876853 470003957576852 470003250576856 470001712276856 470004335276852 470004301876857 470004132876859 470000644176852 470002568076850 $15 off $50 coupons: 470003120776324 470001366376322 470000364576321 470003891676328 470002775976325 470002262276327 470002913376321 470002905576326 470002347376324 470003340876323
Output for 7.1.5
10% off coupons: 470001818476853 470003714376855 470003669276859 470001130776853 470004813776850 470000927176852 470002814576851 470000585076853 470000825776857 470001382776854 $15 off $50 coupons: 470001217176323 470000550076321 470002537976327 470003129476324 470004555276328 470002576976326 470004769076325 470004792376324 470001284476326 470000268476321
Output for 7.1.4
10% off coupons: 470001953076857 470003326176850 470004553576857 470001670776856 470003178076858 470004424676853 470000450376859 470001401076859 470002913876852 470001163676854 $15 off $50 coupons: 470000531376327 470000754976328 470001534976323 470000350976326 470001373876327 470003420976325 470001410276325 470002576376324 470000292576325 470002158576326
Output for 7.1.3
10% off coupons: 470002109076851 470004254276858 470004391876850 470001632376858 470003395676855 470000964576851 470000687876856 470003974476852 470003367876856 470001866676854 $15 off $50 coupons: 470004220976324 470002840776324 470002859776322 470001836176322 470002944976323 470001820976327 470004374976324 470004949976322 470003544776320 470001258976326
Output for 7.1.2
10% off coupons: 470003526676853 470001437476852 470002917776851 470004589076857 470004412376857 470001313976858 470001204676850 470004909376858 470000159176859 470000908676852 $15 off $50 coupons: 470004916576326 470001486676326 470001377276321 470003733476321 470003929976321 470004379976329 470000467876328 470000818676324 470004265876320 470004559976323
Output for 7.1.1
10% off coupons: 470003398176857 470002683176855 470000656876856 470004944876856 470000708576857 470003517376854 470003865376858 470004234976853 470004610276850 470001737276855 $15 off $50 coupons: 470001696476327 470003537376322 470002247276328 470001987576323 470002246176322 470002446976326 470001716576327 470000824276327 470004659676321 470002756376328
Output for 7.1.0
10% off coupons: 470001861376858 470003915376852 470001627876851 470002668876855 470002168876850 470000282576854 470002469076850 470001941176859 470000165076853 470001313576850 $15 off $50 coupons: 470004155076328 470004211376324 470003807576322 470002991176325 470000679876321 470001402376323 470004883776323 470000440876321 470002122376327 470004881576321
Output for 7.0.20
10% off coupons: 470004103776850 470000917176855 470002636176857 470002486676859 470003900476857 470002874676850 470000575976859 470002886076853 470003765976851 470001805676853 $15 off $50 coupons: 470000872676322 470001425176320 470001437276322 470004969076323 470002877376320 470004505476327 470004241276328 470001357476321 470003931376324 470003485776328
Output for 7.0.19
10% off coupons: 470001976776857 470002579876852 470002817476851 470002796076851 470001722176856 470002830576859 470000291576852 470003935776854 470003572576855 470000349976856 $15 off $50 coupons: 470002334076329 470002241776329 470002476576329 470004625176329 470000309976322 470000498876328 470001605476325 470004792776322 470001547076324 470002663276322
Output for 7.0.18
10% off coupons: 470000591376855 470004156976856 470004799576857 470004700376859 470002292876856 470002644676851 470000822076851 470004868676853 470002538476857 470002394576852 $15 off $50 coupons: 470003901876328 470001390176325 470004519776321 470001443976322 470001520976320 470002490076324 470000389276329 470002111376321 470000376176328 470003550276326
Output for 7.0.17
10% off coupons: 470000285776855 470002979876858 470001921676850 470004182976851 470003219876850 470004195576857 470004631576854 470003615176851 470002549376856 470004415476851 $15 off $50 coupons: 470004441076322 470001289176320 470001643576322 470003695376325 470003482076322 470003793476323 470003272976320 470003957176328 470000750776328 470000909476321
Output for 7.0.16
10% off coupons: 470001536676856 470004277376856 470004695576852 470000142876858 470004841776853 470004650276858 470003440476850 470001855676858 470002837076857 470004750076853 $15 off $50 coupons: 470002565976320 470000250776323 470004745476323 470003450976326 470003519076325 470000169276327 470004910976320 470001932576323 470002466876323 470004506176325
Output for 7.0.15
10% off coupons: 470001446976855 470003355376856 470002849576857 470000375676850 470003703676850 470000735976859 470004576076853 470004640176854 470002865876856 470002228676857 $15 off $50 coupons: 470002694876324 470000266776324 470000767276323 470002567876321 470002346176321 470004847876328 470003680176329 470000315376321 470002281776327 470002256976325
Output for 7.0.14
10% off coupons: 470001158076850 470000718176856 470000668876851 470002431876853 470003897876852 470004667476852 470003373776850 470002943276851 470000424976856 470003435876856 $15 off $50 coupons: 470000803276324 470001632976324 470000579876322 470000370376328 470004153576325 470004263576321 470000942976321 470004245676322 470002399876322 470002335876324
Output for 7.0.13
10% off coupons: 470000380776859 470003411876856 470000102076854 470000729076855 470003226676856 470002129776854 470003602576855 470002603576857 470004708876856 470004957176851 $15 off $50 coupons: 470002750176320 470002977876324 470002231376324 470003855476322 470003433476324 470000812476326 470003862776323 470000787976326 470004259876329 470002548376321
Output for 7.0.12
10% off coupons: 470000669276858 470002189176854 470000869476850 470002694376855 470002218376859 470000831376850 470004125476851 470001538976855 470004484876859 470004724076858 $15 off $50 coupons: 470001947676322 470003852976320 470000804976322 470003385476328 470001229676323 470001399176326 470003812676321 470002968176327 470003111176324 470003205376326
Output for 7.0.11
10% off coupons: 470002460876855 470003911576850 470002174776854 470003954476858 470004852076850 470001530176857 470000825376859 470004617676851 470003403976854 470003193976850 $15 off $50 coupons: 470000354376320 470000372876321 470001852776322 470003735776320 470000480576328 470001731676323 470004106576327 470003358176323 470000397776323 470001946476329
Output for 7.0.10
10% off coupons: 470001956976857 470003691376855 470001613076852 470000116976850 470003760176850 470001461676853 470001461176858 470000798476853 470004200876859 470004642276859 $15 off $50 coupons: 470000199976327 470001973076325 470003504776322 470004943276329 470004174076323 470000193976323 470000711076320 470003409076329 470001905676326 470001963376329
Output for 7.0.9
10% off coupons: 470004778076859 470000276476856 470002985776852 470001593976852 470003849376850 470001946876853 470001641576850 470000443376859 470001103076850 470000800976852 $15 off $50 coupons: 470001663876327 470003561076328 470004732776320 470003980476327 470002691376322 470004530476323 470002208476323 470003974376329 470000165176324 470002868276325
Output for 7.0.8
10% off coupons: 470000478676856 470002289676858 470004375076856 470001330276856 470000140676856 470001336776855 470003123676850 470003770276854 470001764976858 470001245876851 $15 off $50 coupons: 470004463576329 470001537476325 470003637976323 470001808276326 470002900676328 470000540176321 470001755676323 470003305176321 470000975776325 470002305576322
Output for 7.0.7
10% off coupons: 470004199376859 470001412976858 470000555076852 470000151276854 470000843076854 470002897476857 470001457776857 470001901476852 470000333976855 470000892476858 $15 off $50 coupons: 470001669676327 470001181176329 470003905876324 470003169376325 470000750576324 470002203576325 470004843076326 470002906276324 470001589176327 470004452676320
Output for 7.0.6
10% off coupons: 470002121576858 470004435476855 470002425476854 470001964276857 470000919276850 470000698976859 470003233176851 470002594176852 470000238676850 470003642676850 $15 off $50 coupons: 470004546276320 470000546976321 470001738976327 470003563176323 470002693776328 470002983576324 470003583576325 470001354876322 470004688376322 470001133476323
Output for 7.0.5
10% off coupons: 470003597576854 470004799276856 470002653576852 470001355476859 470003366876857 470002948576857 470003123876854 470003194476854 470002145776852 470004407176851 $15 off $50 coupons: 470004256276320 470001945876328 470004790376326 470000619776322 470002499176322 470001262376327 470004183776320 470004526376323 470003344176320 470003432576322
Output for 7.0.4
10% off coupons: 470003177976852 470000714976856 470004161176852 470001974876856 470001691876856 470002374876859 470004827676856 470001126876857 470004964076854 470002109676853 $15 off $50 coupons: 470000610276326 470000445476328 470002613876329 470004959476324 470003978176321 470003520076321 470000813276321 470000996776328 470004526476320 470004297476321
Output for 7.0.3
10% off coupons: 470000520676858 470003874476853 470003424276858 470003953776850 470001810576858 470001503276850 470000101776854 470002275576858 470002985576858 470001876176856 $15 off $50 coupons: 470004566276324 470002352276329 470004579576329 470002911876328 470002737976325 470002592076321 470000219576322 470002929776320 470002217076323 470004804976320
Output for 7.0.2
10% off coupons: 470003319176850 470000179776855 470001549776857 470001922676859 470004212876854 470004375576851 470003457176859 470002583076859 470004312976850 470002855276857 $15 off $50 coupons: 470001252376320 470003745276322 470004560376327 470000696076322 470003329776323 470004433276327 470002899276325 470002786576323 470001808676324 470003289676329
Output for 7.0.1
10% off coupons: 470003827876853 470003276576854 470004372776858 470001980676853 470004261576859 470000152776858 470001421276857 470002611576856 470001962476853 470002790076857 $15 off $50 coupons: 470002157576327 470000774476327 470000819976324 470003170476328 470003400976321 470004325176322 470000732176320 470002208376326 470000696376323 470000966476326
Output for 7.0.0
10% off coupons: 470002875476855 470004508676854 470003645676857 470000471876857 470001891676850 470000333376853 470000687576855 470002648776854 470000537176853 470004794076857 $15 off $50 coupons: 470000847576329 470002260476323 470002692476328 470003983576321 470002533976321 470002849376327 470001483076327 470001995976320 470000458176321 470002346476322
Output for hhvm-3.15.4
10% off coupons: 470000314776856 470002145276857 470000743876851 470003632676853 470002340476854 470000514776854 470003589076850 470004994976858 470001392576857 470003213576855 $15 off $50 coupons: 470001675176323 470001657776329 470000129076325 470004945176320 470004911876322 470002988976327 470000859876325 470000248776328 470002773476322 470003214276327
Output for 5.6.30
10% off coupons: 470002228076855 470004178276859 470002767676851 470001187276856 470001563976851 470004818076856 470003733076859 470000794776858 470004791676852 470000426176858 $15 off $50 coupons: 470000102376329 470000599176327 470004915576327 470000343476321 470004220676323 470001515876321 470001273576327 470002843376323 470004898476324 470004283576325
Output for 5.6.29
10% off coupons: 470003858176854 470004268676859 470000215376858 470000446976858 470002708376857 470003674676859 470000496376851 470001726276859 470003309976859 470000686476859 $15 off $50 coupons: 470002822476327 470001327976325 470002303376320 470000627176329 470001999976326 470001937476321 470004240176322 470000860876321 470001221476327 470001782276329
Output for 5.6.28
10% off coupons: 470000381176856 470002406776850 470000167376852 470001238676857 470000880276859 470001788676857 470002625076854 470004117876850 470001121076856 470001919776852 $15 off $50 coupons: 470004813976328 470000680376322 470002706976325 470004360376329 470002156676325 470002677076321 470001985176327 470004617176320 470000430876324 470003262276324
Output for 5.6.27
10% off coupons: 470002562276850 470001395476857 470004279776852 470003978676852 470001302476857 470001308476851 470004282976850 470000751176851 470001249176858 470002410276858 $15 off $50 coupons: 470000578176324 470004895376320 470003123176329 470001961076320 470004557876328 470000359676326 470000550876327 470003893476322 470003296876323 470004118576322
Output for 5.6.26
10% off coupons: 470000481876854 470002131976853 470001287176858 470004909476855 470002157276852 470003474476857 470004856276850 470004277976858 470002820076857 470002886376854 $15 off $50 coupons: 470003703676324 470004627876326 470003997176326 470000477176326 470004637276321 470004182976325 470000452976323 470000381276327 470003186176328 470001253976321
Output for 5.6.25
10% off coupons: 470004246176852 470003505976851 470001794976859 470001339876859 470003465976854 470002838176853 470003376576853 470004319576855 470003529376859 470000117776855 $15 off $50 coupons: 470004714276329 470000169976326 470002120076328 470001810076327 470000683076328 470003129776325 470004421776327 470002266976322 470000802076321 470002769576326
Output for 5.6.24
10% off coupons: 470002418176853 470002288076857 470001857576859 470000432976855 470003868376855 470002550576856 470003629076857 470001841876859 470001147876850 470000252976851 $15 off $50 coupons: 470003299876320 470001374576325 470000317476326 470001753476321 470002779076328 470002178076325 470000963276325 470001494476321 470004515376327 470004570276327
Output for 5.6.23
10% off coupons: 470002363976850 470001336076856 470000276776857 470002144976857 470000524476850 470002437376852 470004240176858 470003320476857 470002596876859 470003442276854 $15 off $50 coupons: 470002443576321 470000113776323 470001933276321 470002226476329 470000883476324 470000603976325 470000457876321 470004352476327 470002323076323 470001744776324
Output for 5.6.22
10% off coupons: 470002614876854 470002413976854 470001337776854 470004179576859 470004507276857 470003280976855 470002987676853 470004669376853 470001725576851 470000575976859 $15 off $50 coupons: 470004743176324 470003969376327 470002540076328 470004617976326 470001160676321 470001822776321 470003893076324 470000117976323 470000144876320 470000994676323
Output for 5.6.21
10% off coupons: 470002311976857 470002130776850 470004696676858 470000812576859 470003509376855 470001710776853 470003360176854 470001700776856 470003549676854 470000240776852 $15 off $50 coupons: 470004683776325 470001611676320 470003340876323 470000742076320 470000139576327 470001705776325 470001841976320 470003282676326 470002860176326 470004220676323
Output for 5.6.20
10% off coupons: 470001187876858 470001728676855 470002401576851 470003425576858 470001274776856 470000164676856 470003873176853 470004544276858 470004623676852 470003640576855 $15 off $50 coupons: 470004800976324 470003735676323 470002520576329 470003146976326 470003810776320 470001867976328 470004698976321 470002496276322 470000333576321 470004285476326
Output for 5.6.19
10% off coupons: 470003307876854 470001457376859 470002604776850 470003803076857 470000713876850 470003451876854 470003408276850 470001599476851 470001208776853 470000413076857 $15 off $50 coupons: 470004198576328 470003283776322 470002833676327 470003752376329 470002305376328 470003308276325 470002939776327 470003139176320 470002356976324 470004713376327
Output for 5.6.18
10% off coupons: 470001683976854 470000247176853 470001235676850 470002833376852 470003254476855 470001802976857 470002234476854 470003427876857 470000852076852 470002102976851 $15 off $50 coupons: 470003754176323 470003243976328 470003978676326 470002428976320 470000763476321 470001520976320 470001448276328 470003733976326 470002196076321 470002285276328
Output for 5.6.17
10% off coupons: 470001354076852 470002736976852 470003821476851 470000368076858 470002923576858 470004947276851 470002755376855 470002758276855 470002894076852 470000967176850 $15 off $50 coupons: 470003129876322 470003351976326 470001595176328 470001139576324 470002605576329 470000817676325 470004797976321 470002677976324 470002604976328 470004101176324
Output for 5.6.16
10% off coupons: 470002484976852 470000724476858 470002664076853 470001716476856 470003157076855 470001724376858 470001307676856 470003298176858 470003167276856 470003808076852 $15 off $50 coupons: 470000218276322 470003831476322 470004452276322 470000967176324 470000141876323 470001621676327 470002452976327 470001965876322 470000646576322 470003722376328
Output for 5.6.15
10% off coupons: 470000496076850 470004991676850 470000127376854 470001349076850 470004115176853 470002228576850 470001775276855 470003209876853 470001868976853 470001774676854 $15 off $50 coupons: 470001657776329 470003353476329 470000743376320 470000518676327 470003401676329 470002794976320 470003597576328 470003895076322 470002236476326 470000553176325
Output for 5.6.14
10% off coupons: 470000677076853 470000617476859 470002769676859 470000590076855 470003756376851 470004746676852 470004601076858 470000912776852 470000902876852 470002942376859 $15 off $50 coupons: 470001649076321 470004835576322 470004855376322 470003815376327 470003449076327 470004763976324 470000929176324 470001609076323 470003545276324 470000423776327
Output for 5.6.13
10% off coupons: 470004332076851 470003642776857 470003534676852 470003396276856 470000425276856 470003597276853 470003999276857 470004673476853 470004542376857 470000772576852 $15 off $50 coupons: 470003739576322 470001806976327 470003353876327 470000236376325 470003575176328 470004641476328 470003683776328 470001545576321 470000838976329 470004232276320
Output for 5.6.12
10% off coupons: 470001653076850 470001810076853 470000232576859 470000460076855 470000404976852 470003508876851 470003776276858 470000751076854 470002630376857 470004751376853 $15 off $50 coupons: 470002534176324 470000927076329 470000970176328 470003557576320 470000954676325 470003392376321 470002933976327 470000635676323 470000262776328 470004224176324
Output for 5.6.11
10% off coupons: 470004653176858 470000992076859 470004929776850 470000950276857 470003494076853 470000168076850 470001383876850 470001891376859 470001742676855 470001106176854 $15 off $50 coupons: 470004761276327 470000640376324 470003162176328 470003836476327 470003928876325 470002613476321 470002739576325 470002491376324 470003741476320 470001436576324
Output for 5.6.10
10% off coupons: 470004538976856 470003278976850 470003121776859 470002417776856 470000348576859 470004551276858 470004322176851 470003201876851 470000521376856 470001227176856 $15 off $50 coupons: 470002267276322 470000103676329 470001967876320 470004473176328 470000975976329 470002993776325 470002393476320 470000170576324 470001777676325 470002486276325
Output for 5.6.9
10% off coupons: 470001618576852 470003528476857 470001418976852 470001311876853 470001214976858 470003380976854 470001837776859 470003948676851 470003758176855 470002856076852 $15 off $50 coupons: 470001839876328 470004886276325 470001276776328 470001597876325 470000580676324 470001431976327 470000923776322 470004506776327 470001298776320 470003667276325
Output for 5.6.8
10% off coupons: 470000539376855 470004815976852 470000324676856 470003526576856 470000816676852 470001760176856 470001490876859 470000926176853 470004336176854 470001995376854 $15 off $50 coupons: 470001936376325 470004220876327 470001832476327 470003799676321 470004350776320 470000159876322 470003228676328 470004964376329 470001598676320 470002594876325
Output for 5.6.7
10% off coupons: 470000178176854 470000202676855 470001997476859 470002293576854 470001591276855 470000915176857 470004877176856 470001287376852 470001726276859 470000986576853 $15 off $50 coupons: 470002106876324 470002186076324 470001512776327 470001556976325 470002505776324 470002556676321 470002662176326 470003916676326 470003181776325 470000890276320
Output for 5.6.6
10% off coupons: 470001650876859 470002661376857 470003149876852 470001961676858 470002257776856 470002178576856 470003678876859 470004224976856 470004977276852 470000357076852 $15 off $50 coupons: 470000936176324 470004494876320 470000943676329 470004650376329 470002764576321 470004893976324 470001363576329 470002153976329 470001800976323 470000939476322
Output for 5.6.5
10% off coupons: 470003583776855 470002934076859 470004527276851 470003703776857 470000877176858 470003702176856 470002770076853 470001517776858 470002665876858 470001789676856 $15 off $50 coupons: 470002638376323 470001883676325 470003271976321 470002806776320 470002260976328 470001335676323 470003829976322 470000705576324 470001815376323 470001382276323
Output for 5.6.4
10% off coupons: 470002681776859 470001257676852 470000472876856 470002832076852 470001394776859 470002262276853 470001484476850 470001612376854 470002602676855 470002511076852 $15 off $50 coupons: 470004904976329 470002343776326 470003681376322 470004975176321 470000194776328 470000750876325 470003462376329 470004892176329 470004416576321 470003206976327
Output for 5.6.3
10% off coupons: 470003168476859 470001251676858 470003841476855 470004114276851 470004198276853 470002529476859 470001100876859 470002215276855 470003658576854 470004953276852 $15 off $50 coupons: 470002593276324 470002652176329 470001326876329 470002331876328 470003209876327 470002476376325 470000931176329 470002844776320 470003585676320 470004744976329
Output for 5.6.2
10% off coupons: 470003113376852 470004199276852 470001191176852 470004163576858 470002511276856 470000569976858 470004825776855 470000368476856 470001707376851 470001721076850 $15 off $50 coupons: 470003477476328 470004496776321 470004771976323 470003127376329 470002510376328 470001149276320 470002266776328 470000833776320 470001992576325 470004842476325
Output for 5.6.1
10% off coupons: 470004423076852 470001934976855 470001241576854 470003557276855 470000233476851 470003873776855 470004828376854 470004401376851 470003581476856 470002933276854 $15 off $50 coupons: 470002736676325 470004406776328 470004227676326 470002819776324 470004356176322 470002765676327 470003848476322 470003118476328 470004363976328 470002245276320
Output for 5.6.0
10% off coupons: 470001926376854 470001542176852 470002603176859 470001232876857 470001890576854 470003921176859 470000183076859 470003670376852 470004422676855 470002991976857 $15 off $50 coupons: 470000997176325 470000620076329 470002195976325 470001579076323 470002924776325 470001867276329 470004557276326 470001414176324 470000763976326 470002448876327