3v4l.org

run code in 300+ PHP versions simultaneously
<?php function GetLuhnCheckDigit($number) { $sum = 0; $alt = true; $digits = str_split($number); for ($i = count($digits) - 1; $i >= 0; $i--) { $curDigit = $digits[$i]; if ($alt) { $curDigit *= 2; if ($curDigit > 9) $curDigit -= 9; } $sum += $curDigit; $alt = false; } if (($sum % 10) == 0 ){ return 0; } echo abs($sum) . PHP_EOL; return (10 - (abs($sum) % 10)); } echo GetLuhnCheckDigit(12345678912345678918);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tM4L0
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'getluhncheckdigit'
          1        SEND_VAL                                                 1.23457e+19
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function getluhncheckdigit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 11
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
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: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 11
Branch analysis from position: 23
Branch analysis from position: 11
Branch analysis from position: 18
Branch analysis from position: 18
filename:       /in/tM4L0
function name:  GetLuhnCheckDigit
number of ops:  39
compiled vars:  !0 = $number, !1 = $sum, !2 = $alt, !3 = $digits, !4 = $i, !5 = $curDigit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, 0
    5     2        ASSIGN                                                   !2, <true>
    6     3        INIT_FCALL                                               'str_split'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !3, $8
    7     7        COUNT                                            ~10     !3
          8        SUB                                              ~11     ~10, 1
          9        ASSIGN                                                   !4, ~11
         10      > JMP                                                      ->21
    8    11    >   FETCH_DIM_R                                      ~13     !3, !4
         12        ASSIGN                                                   !5, ~13
    9    13      > JMPZ                                                     !2, ->18
   10    14    >   ASSIGN_OP                                     3          !5, 2
   11    15        IS_SMALLER                                               9, !5
         16      > JMPZ                                                     ~16, ->18
   12    17    >   ASSIGN_OP                                     2          !5, 9
   14    18    >   ASSIGN_OP                                     1          !1, !5
   15    19        ASSIGN                                                   !2, <false>
    7    20        PRE_DEC                                                  !4
         21    >   IS_SMALLER_OR_EQUAL                                      0, !4
         22      > JMPNZ                                                    ~21, ->11
   17    23    >   MOD                                              ~22     !1, 10
         24        IS_EQUAL                                                 ~22, 0
         25      > JMPZ                                                     ~23, ->27
   18    26    > > RETURN                                                   0
   20    27    >   INIT_FCALL                                               'abs'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $24     
         30        CONCAT                                           ~25     $24, '%0A'
         31        ECHO                                                     ~25
   21    32        INIT_FCALL                                               'abs'
         33        SEND_VAR                                                 !1
         34        DO_ICALL                                         $26     
         35        MOD                                              ~27     $26, 10
         36        SUB                                              ~28     10, ~27
         37      > RETURN                                                   ~28
   22    38*     > RETURN                                                   null

End of function getluhncheckdigit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.61 ms | 1403 KiB | 18 Q