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 = array_reduce( array_reverse(str_split($refBase)), function($result, $v) { static $i; $i ??= 0; return $result + ($v * WEIGHTS[$i++ % WEIGHTS_COUNT]); }, 0 ); echo $refBase . (ceil($weightedSum / 10) * 10 - $weightedSum);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ig8GS
function name:  (null)
number of ops:  40
compiled vars:  !0 = $customerNumber, !1 = $invoiceNumber, !2 = $refBase, !3 = $weightedSum
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                                   ~5      'WEIGHTS'
          7        COUNT                                            ~6      ~5
          8        SEND_VAL                                                 ~6
          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                                         $10     
         17        ASSIGN                                                   !2, $10
   11    18        INIT_FCALL                                               'array_reduce'
   12    19        INIT_FCALL                                               'array_reverse'
         20        INIT_FCALL                                               'str_split'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $12     
         23        SEND_VAR                                                 $12
         24        DO_ICALL                                         $13     
         25        SEND_VAR                                                 $13
   13    26        DECLARE_LAMBDA_FUNCTION                          ~14     [0]
   17    27        SEND_VAL                                                 ~14
   18    28        SEND_VAL                                                 0
   11    29        DO_ICALL                                         $15     
         30        ASSIGN                                                   !3, $15
   21    31        INIT_FCALL                                               'ceil'
         32        DIV                                              ~17     !3, 10
         33        SEND_VAL                                                 ~17
         34        DO_ICALL                                         $18     
         35        MUL                                              ~19     $18, 10
         36        SUB                                              ~20     ~19, !3
         37        CONCAT                                           ~21     !2, ~20
         38        ECHO                                                     ~21
         39      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ig8GS
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $result, !1 = $v, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        BIND_STATIC                                              !2
   15     3        COALESCE                                         ~3      !2
          4        ASSIGN                                           ~4      !2, 0
          5        QM_ASSIGN                                        ~3      ~4
          6        FREE                                                     ~3
   16     7        FETCH_CONSTANT                                   ~5      'WEIGHTS'
          8        POST_INC                                         ~6      !2
          9        FETCH_CONSTANT                                   ~7      'WEIGHTS_COUNT'
         10        MOD                                              ~8      ~6, ~7
         11        FETCH_DIM_R                                      ~9      ~5, ~8
         12        MUL                                              ~10     !1, ~9
         13        ADD                                              ~11     !0, ~10
         14      > RETURN                                                   ~11
   17    15*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.77 ms | 1021 KiB | 19 Q