3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Get luhn checksum * * @param $str_string * @param $int_base * @return string */ function get_luhn_checksum($str_string, $int_base) { $arr_chars = array_reverse(str_split($str_string)); $int_check_sum = 0; foreach ($arr_chars AS $int_index=>$str_char) { $int_adjustment = ((int)base_convert($str_char, $int_base, 10)) * ($int_index % 2 ? 1 : 2); $int_check_sum += $int_adjustment; echo "char $int_index is $str_char adjustment is +$int_adjustment running checksum is $int_check_sum\n"; } echo "Final checksum is $int_check_sum modded = " . ($int_check_sum % $int_base) . "\n"; return strtoupper(base_convert($int_base - ($int_check_sum % $int_base), 10, $int_base)); } echo get_luhn_checksum('7992739871', 10); exit; $str = get_luhn_checksum('0B022412500000009104', 16); echo $str;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/aqU8h
function name:  (null)
number of ops:  13
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'get_luhn_checksum'
          1        SEND_VAL                                                 '7992739871'
          2        SEND_VAL                                                 10
          3        DO_FCALL                                      0  $1      
          4        ECHO                                                     $1
   23     5      > EXIT                                                     
   24     6*       INIT_FCALL                                               'get_luhn_checksum'
          7*       SEND_VAL                                                 '0B022412500000009104'
          8*       SEND_VAL                                                 16
          9*       DO_FCALL                                      0  $2      
         10*       ASSIGN                                                   !0, $2
   25    11*       ECHO                                                     !0
         12*     > RETURN                                                   1

Function get_luhn_checksum:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 38
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 38
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/aqU8h
function name:  get_luhn_checksum
number of ops:  58
compiled vars:  !0 = $str_string, !1 = $int_base, !2 = $arr_chars, !3 = $int_check_sum, !4 = $str_char, !5 = $int_index, !6 = $int_adjustment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        INIT_FCALL                                               'array_reverse'
          3        INIT_FCALL                                               'str_split'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        SEND_VAR                                                 $7
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !2, $8
   12     9        ASSIGN                                                   !3, 0
   13    10      > FE_RESET_R                                       $11     !2, ->38
         11    > > FE_FETCH_R                                       ~12     $11, !4, ->38
         12    >   ASSIGN                                                   !5, ~12
   14    13        INIT_FCALL                                               'base_convert'
         14        SEND_VAR                                                 !4
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 10
         17        DO_ICALL                                         $14     
         18        CAST                                          4  ~15     $14
         19        MOD                                              ~16     !5, 2
         20      > JMPZ                                                     ~16, ->23
         21    >   QM_ASSIGN                                        ~17     1
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~17     2
         24    >   MUL                                              ~18     ~15, ~17
         25        ASSIGN                                                   !6, ~18
   15    26        ASSIGN_OP                                     1          !3, !6
   16    27        ROPE_INIT                                     9  ~22     'char+'
         28        ROPE_ADD                                      1  ~22     ~22, !5
         29        ROPE_ADD                                      2  ~22     ~22, '+is+'
         30        ROPE_ADD                                      3  ~22     ~22, !4
         31        ROPE_ADD                                      4  ~22     ~22, '+adjustment+is+%2B'
         32        ROPE_ADD                                      5  ~22     ~22, !6
         33        ROPE_ADD                                      6  ~22     ~22, '+running+checksum+is+'
         34        ROPE_ADD                                      7  ~22     ~22, !3
         35        ROPE_END                                      8  ~21     ~22, '%0A'
         36        ECHO                                                     ~21
   13    37      > JMP                                                      ->11
         38    >   FE_FREE                                                  $11
   18    39        ROPE_INIT                                     3  ~28     'Final+checksum+is+'
         40        ROPE_ADD                                      1  ~28     ~28, !3
         41        ROPE_END                                      2  ~27     ~28, '+modded+%3D+'
         42        MOD                                              ~30     !3, !1
         43        CONCAT                                           ~31     ~27, ~30
         44        CONCAT                                           ~32     ~31, '%0A'
         45        ECHO                                                     ~32
   19    46        INIT_FCALL                                               'strtoupper'
         47        INIT_FCALL                                               'base_convert'
         48        MOD                                              ~33     !3, !1
         49        SUB                                              ~34     !1, ~33
         50        SEND_VAL                                                 ~34
         51        SEND_VAL                                                 10
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                         $35     
         54        SEND_VAR                                                 $35
         55        DO_ICALL                                         $36     
         56      > RETURN                                                   $36
   20    57*     > RETURN                                                   null

End of function get_luhn_checksum

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.48 ms | 1403 KiB | 23 Q