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] - 48); 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(1234567891234567891);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sYeh4
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                                                 1234567891234567891
          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 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 11
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 11
Branch analysis from position: 24
Branch analysis from position: 11
Branch analysis from position: 19
Branch analysis from position: 19
filename:       /in/sYeh4
function name:  GetLuhnCheckDigit
number of ops:  40
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                                                      ->22
    8    11    >   FETCH_DIM_R                                      ~13     !3, !4
         12        SUB                                              ~14     ~13, 48
         13        ASSIGN                                                   !5, ~14
    9    14      > JMPZ                                                     !2, ->19
   10    15    >   ASSIGN_OP                                     3          !5, 2
   11    16        IS_SMALLER                                               9, !5
         17      > JMPZ                                                     ~17, ->19
   12    18    >   ASSIGN_OP                                     2          !5, 9
   14    19    >   ASSIGN_OP                                     1          !1, !5
   15    20        ASSIGN                                                   !2, <false>
    7    21        PRE_DEC                                                  !4
         22    >   IS_SMALLER_OR_EQUAL                                      0, !4
         23      > JMPNZ                                                    ~22, ->11
   17    24    >   MOD                                              ~23     !1, 10
         25        IS_EQUAL                                                 ~23, 0
         26      > JMPZ                                                     ~24, ->28
   18    27    > > RETURN                                                   0
   20    28    >   INIT_FCALL                                               'abs'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $25     
         31        CONCAT                                           ~26     $25, '%0A'
         32        ECHO                                                     ~26
   21    33        INIT_FCALL                                               'abs'
         34        SEND_VAR                                                 !1
         35        DO_ICALL                                         $27     
         36        MOD                                              ~28     $27, 10
         37        SUB                                              ~29     10, ~28
         38      > RETURN                                                   ~29
   22    39*     > RETURN                                                   null

End of function getluhncheckdigit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.16 ms | 1403 KiB | 18 Q