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; } $arr = array(); foreach(range(0,120) as $num) { if ($num % 10 === 0) { $arr[] = $num; } } echo implode(' ,', $arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 12
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/vFdFZ
function name:  (null)
number of ops:  20
compiled vars:  !0 = $arr, !1 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   17     1        INIT_FCALL                                               'range'
          2        SEND_VAL                                                 0
          3        SEND_VAL                                                 120
          4        DO_ICALL                                         $3      
          5      > FE_RESET_R                                       $4      $3, ->13
          6    > > FE_FETCH_R                                               $4, !1, ->13
   18     7    >   MOD                                              ~5      !1, 10
          8        IS_IDENTICAL                                             ~5, 0
          9      > JMPZ                                                     ~6, ->12
   19    10    >   ASSIGN_DIM                                               !0
         11        OP_DATA                                                  !1
   17    12    > > JMP                                                      ->6
         13    >   FE_FREE                                                  $4
   23    14        INIT_FCALL                                               'implode'
         15        SEND_VAL                                                 '+%2C'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $8      
         18        ECHO                                                     $8
         19      > 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/vFdFZ
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:
142.85 ms | 1400 KiB | 19 Q