3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('WEIGHTS', [7, 3, 1]); define('WEIGHTS_COUNT', count(WEIGHTS)); $customerNumber = 1; $invoiceNumber = 25; $refBase = sprintf('%d%04d', $customerNumber, $invoiceNumber); $weightedSum = 0; for ($x = 0, $i = strlen($refBase) - 1; $i >=0; --$i, ++$x) { $weightedSum += $refBase[$i] * WEIGHTS[$x % WEIGHTS_COUNT]; } echo $refBase . (ceil($weightedSum / 10) * 10 - $weightedSum);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 24
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 24
Branch analysis from position: 35
Branch analysis from position: 24
filename:       /in/naOFg
function name:  (null)
number of ops:  44
compiled vars:  !0 = $customerNumber, !1 = $invoiceNumber, !2 = $refBase, !3 = $weightedSum, !4 = $x, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'WEIGHTS'
          2        SEND_VAL                                                 <array>
          3        DO_ICALL                                                 
    4     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'WEIGHTS_COUNT'
          6        FETCH_CONSTANT                                   ~7      'WEIGHTS'
          7        COUNT                                            ~8      ~7
          8        SEND_VAL                                                 ~8
          9        DO_ICALL                                                 
    6    10        ASSIGN                                                   !0, 1
    7    11        ASSIGN                                                   !1, 25
    9    12        INIT_FCALL                                               'sprintf'
         13        SEND_VAL                                                 '%25d%2504d'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !2, $12
   11    18        ASSIGN                                                   !3, 0
   12    19        ASSIGN                                                   !4, 0
         20        STRLEN                                           ~16     !2
         21        SUB                                              ~17     ~16, 1
         22        ASSIGN                                                   !5, ~17
         23      > JMP                                                      ->33
   13    24    >   FETCH_DIM_R                                      ~19     !2, !5
         25        FETCH_CONSTANT                                   ~20     'WEIGHTS'
         26        FETCH_CONSTANT                                   ~21     'WEIGHTS_COUNT'
         27        MOD                                              ~22     !4, ~21
         28        FETCH_DIM_R                                      ~23     ~20, ~22
         29        MUL                                              ~24     ~19, ~23
         30        ASSIGN_OP                                     1          !3, ~24
   12    31        PRE_DEC                                                  !5
         32        PRE_INC                                                  !4
         33    >   IS_SMALLER_OR_EQUAL                                      0, !5
         34      > JMPNZ                                                    ~28, ->24
   16    35    >   INIT_FCALL                                               'ceil'
         36        DIV                                              ~29     !3, 10
         37        SEND_VAL                                                 ~29
         38        DO_ICALL                                         $30     
         39        MUL                                              ~31     $30, 10
         40        SUB                                              ~32     ~31, !3
         41        CONCAT                                           ~33     !2, ~32
         42        ECHO                                                     ~33
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.69 ms | 1012 KiB | 16 Q