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 (luhn($num)) { $arr[] = $num; } } $str = implode(' ,', $arr); echo $str;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
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/VmdmZ
function name:  (null)
number of ops:  22
compiled vars:  !0 = $arr, !1 = $num, !2 = $str
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                                         $4      
          5      > FE_RESET_R                                       $5      $4, ->14
          6    > > FE_FETCH_R                                               $5, !1, ->14
   18     7    >   INIT_FCALL                                               'luhn'
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $6      
         10      > JMPZ                                                     $6, ->13
   19    11    >   ASSIGN_DIM                                               !0
         12        OP_DATA                                                  !1
   17    13    > > JMP                                                      ->6
         14    >   FE_FREE                                                  $5
   23    15        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '+%2C'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $8      
         19        ASSIGN                                                   !2, $8
   24    20        ECHO                                                     !2
         21      > 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/VmdmZ
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:
180.28 ms | 1402 KiB | 20 Q