3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('WEIGHTS', [7, 3, 1]); define('WEIGHTS_COUNT', count(WEIGHTS)); $customerNumber = 1; $invoiceNumber = 25; echo ($refBase = sprintf('%d%04d', $customerNumber, $invoiceNumber)) . $verificationDigit = ( fn($weightedSum) => (ceil($weightedSum / 10) * 10 - $weightedSum) )(array_reduce( str_split(strrev($refBase)), function($result, $v) { static $i; $i ??= 0; return $result + ($v * WEIGHTS[$i++ % WEIGHTS_COUNT]); }, 0 ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q1CvF
function name:  (null)
number of ops:  38
compiled vars:  !0 = $customerNumber, !1 = $invoiceNumber, !2 = $refBase, !3 = $verificationDigit
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                                           ~11     !2, $10
   11    18        DECLARE_LAMBDA_FUNCTION                          ~12     [0]
   12    19        INIT_DYNAMIC_CALL                                        ~12
         20        INIT_FCALL                                               'array_reduce'
   13    21        INIT_FCALL                                               'str_split'
         22        INIT_FCALL                                               'strrev'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $13     
         25        SEND_VAR                                                 $13
         26        DO_ICALL                                         $14     
         27        SEND_VAR                                                 $14
   14    28        DECLARE_LAMBDA_FUNCTION                          ~15     [1]
   18    29        SEND_VAL                                                 ~15
   19    30        SEND_VAL                                                 0
   12    31        DO_ICALL                                         $16     
   19    32        SEND_VAR_NO_REF_EX                                       $16
   12    33        DO_FCALL                                      0  $17     
   10    34        ASSIGN                                           ~18     !3, $17
         35        CONCAT                                           ~19     ~11, ~18
         36        ECHO                                                     ~19
   21    37      > 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/q1CvF
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $weightedSum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'ceil'
          2        DIV                                              ~1      !0, 10
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5        MUL                                              ~3      $2, 10
          6        SUB                                              ~4      ~3, !0
          7      > RETURN                                                   ~4
   12     8*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/q1CvF
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $result, !1 = $v, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        BIND_STATIC                                              !2
   16     3        COALESCE                                         ~3      !2
          4        ASSIGN                                           ~4      !2, 0
          5        QM_ASSIGN                                        ~3      ~4
          6        FREE                                                     ~3
   17     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
   18    15*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.72 ms | 1021 KiB | 19 Q