3v4l.org

run code in 300+ PHP versions simultaneously
<?php function luhn($number) { settype($number, 'string'); $sumTable = array( array(0,1,2,3,4,5,6,7,8,9), array(0,2,4,6,8,1,3,5,7,9)); $sum = 0; $flip = 0; for ($i = strlen($number) - 1; $i >= 0; $i--) { $sum += $sumTable[$flip++ & 0x1][$number[$i]]; } return $sum % 10 === 0; } foreach(range(0,100) as $num) { if (luhn($num)) { echo "$num, "; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/CmEin
function name:  (null)
number of ops:  16
compiled vars:  !0 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 100
          3        DO_ICALL                                         $1      
          4      > FE_RESET_R                                       $2      $1, ->14
          5    > > FE_FETCH_R                                               $2, !0, ->14
   17     6    >   INIT_FCALL                                               'luhn'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $3      
          9      > JMPZ                                                     $3, ->13
   18    10    >   NOP                                                      
         11        FAST_CONCAT                                      ~4      !0, '%2C+'
         12        ECHO                                                     ~4
   16    13    > > JMP                                                      ->5
         14    >   FE_FREE                                                  $2
   20    15      > RETURN                                                   1

Function luhn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 12
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 12
Branch analysis from position: 21
Branch analysis from position: 12
filename:       /in/CmEin
function name:  luhn
number of ops:  25
compiled vars:  !0 = $number, !1 = $sumTable, !2 = $sum, !3 = $flip, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'settype'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 'string'
          4        DO_ICALL                                                 
    5     5        ASSIGN                                                   !1, <array>
    8     6        ASSIGN                                                   !2, 0
    9     7        ASSIGN                                                   !3, 0
   10     8        STRLEN                                           ~9      !0
          9        SUB                                              ~10     ~9, 1
         10        ASSIGN                                                   !4, ~10
         11      > JMP                                                      ->19
   11    12    >   POST_INC                                         ~12     !3
         13        BW_AND                                           ~13     ~12, 1
         14        FETCH_DIM_R                                      ~15     !0, !4
         15        FETCH_DIM_R                                      ~14     !1, ~13
         16        FETCH_DIM_R                                      ~16     ~14, ~15
         17        ASSIGN_OP                                     1          !2, ~16
   10    18        PRE_DEC                                                  !4
         19    >   IS_SMALLER_OR_EQUAL                                      0, !4
         20      > JMPNZ                                                    ~19, ->12
   13    21    >   MOD                                              ~20     !2, 10
         22        IS_IDENTICAL                                     ~21     ~20, 0
         23      > RETURN                                                   ~21
   14    24*     > RETURN                                                   null

End of function luhn

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.78 ms | 1402 KiB | 18 Q