3v4l.org

run code in 300+ PHP versions simultaneously
<?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"); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DCER7
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'generate_upc_checkdigit'
          1        SEND_VAL                                                 '123456'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   31     4      > RETURN                                                   1

Function generate_upc_checkdigit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
Branch analysis from position: 5
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
Branch analysis from position: 5
filename:       /in/DCER7
function name:  generate_upc_checkdigit
number of ops:  30
compiled vars:  !0 = $upc_code, !1 = $odd_total, !2 = $even_total, !3 = $i, !4 = $sum, !5 = $check_digit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, 0
    7     2        ASSIGN                                                   !2, 0
    9     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->15
   11     5    >   ADD                                              ~9      !3, 1
          6        MOD                                              ~10     ~9, 2
          7        IS_EQUAL                                                 ~10, 0
          8      > JMPZ                                                     ~11, ->12
   13     9    >   FETCH_DIM_R                                      ~12     !0, !3
         10        ASSIGN_OP                                     1          !2, ~12
         11      > JMP                                                      ->14
   16    12    >   FETCH_DIM_R                                      ~14     !0, !3
         13        ASSIGN_OP                                     1          !1, ~14
    9    14    >   PRE_INC                                                  !3
         15    >   IS_SMALLER                                               !3, 7
         16      > JMPNZ                                                    ~17, ->5
   20    17    >   MUL                                              ~18     !1, 3
         18        ADD                                              ~19     ~18, !2
         19        ASSIGN                                                   !4, ~19
   23    20        MOD                                              ~21     !4, 10
         21        ASSIGN                                                   !5, ~21
   26    22        IS_SMALLER                                               0, !5
         23      > JMPZ                                                     ~23, ->27
         24    >   SUB                                              ~24     10, !5
         25        QM_ASSIGN                                        ~25     ~24
         26      > JMP                                                      ->28
         27    >   QM_ASSIGN                                        ~25     !5
         28    > > RETURN                                                   ~25
   27    29*     > RETURN                                                   null

End of function generate_upc_checkdigit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.35 ms | 1403 KiB | 14 Q