3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ean_checksum($eancode) { if(strlen($eancode) != 12) { return '-1'; } $oddsum=0; $evensum=0; $total=0; $eanvalue=$eancode; $finalean = strrev(substr($eanvalue,0,12)); for($i=0;$i<strlen($finalean);$i++) { if(($i % 2) == 0) { $oddsum += intval($finalean[$i]); } else { $evensum += intval($finalean[$i]); } } $total=($oddsum * 3) + $evensum; $check = intval(10 - ceil($total % 10.0)) %10; return $check; } $ean = '037007923000'; echo ean_checksum($ean);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D8iMK
function name:  (null)
number of ops:  6
compiled vars:  !0 = $ean
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, '037007923000'
   29     1        INIT_FCALL                                               'ean_checksum'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function ean_checksum:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 20
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 20
Branch analysis from position: 34
Branch analysis from position: 20
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 20
Branch analysis from position: 34
Branch analysis from position: 20
filename:       /in/D8iMK
function name:  ean_checksum
number of ops:  47
compiled vars:  !0 = $eancode, !1 = $oddsum, !2 = $evensum, !3 = $total, !4 = $eanvalue, !5 = $finalean, !6 = $i, !7 = $check
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        STRLEN                                           ~8      !0
          2        IS_NOT_EQUAL                                             ~8, 12
          3      > JMPZ                                                     ~9, ->5
    4     4    > > RETURN                                                   '-1'
    7     5    >   ASSIGN                                                   !1, 0
    8     6        ASSIGN                                                   !2, 0
    9     7        ASSIGN                                                   !3, 0
   10     8        ASSIGN                                                   !4, !0
   11     9        INIT_FCALL                                               'strrev'
         10        INIT_FCALL                                               'substr'
         11        SEND_VAR                                                 !4
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 12
         14        DO_ICALL                                         $14     
         15        SEND_VAR                                                 $14
         16        DO_ICALL                                         $15     
         17        ASSIGN                                                   !5, $15
   13    18        ASSIGN                                                   !6, 0
         19      > JMP                                                      ->31
   14    20    >   MOD                                              ~18     !6, 2
         21        IS_EQUAL                                                 ~18, 0
         22      > JMPZ                                                     ~19, ->27
   15    23    >   FETCH_DIM_R                                      ~20     !5, !6
         24        CAST                                          4  ~21     ~20
         25        ASSIGN_OP                                     1          !1, ~21
         26      > JMP                                                      ->30
   18    27    >   FETCH_DIM_R                                      ~23     !5, !6
         28        CAST                                          4  ~24     ~23
         29        ASSIGN_OP                                     1          !2, ~24
   13    30    >   PRE_INC                                                  !6
         31    >   STRLEN                                           ~27     !5
         32        IS_SMALLER                                               !6, ~27
         33      > JMPNZ                                                    ~28, ->20
   21    34    >   MUL                                              ~29     !1, 3
         35        ADD                                              ~30     ~29, !2
         36        ASSIGN                                                   !3, ~30
   23    37        INIT_FCALL                                               'ceil'
         38        MOD                                              ~32     !3, 10
         39        SEND_VAL                                                 ~32
         40        DO_ICALL                                         $33     
         41        SUB                                              ~34     10, $33
         42        CAST                                          4  ~35     ~34
         43        MOD                                              ~36     ~35, 10
         44        ASSIGN                                                   !7, ~36
   24    45      > RETURN                                                   !7
   25    46*     > RETURN                                                   null

End of function ean_checksum

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.12 ms | 1403 KiB | 20 Q