3v4l.org

run code in 300+ PHP versions simultaneously
<?php function repeatInt(int $val, int $min, int $max) { $listLength = $max - $min + 1; $key = ($val % $listLength) % $listLength; if ($key < 0) { $key = $listLength + ($key % $listLength); } return $key; } echo 'Test 2 to 5' . PHP_EOL; echo '---------------------------------' . PHP_EOL; foreach (range(-10, 10) as $i) { echo $i . ' → ' . repeatInt($i, 2, 5) . PHP_EOL; } echo PHP_EOL; echo 'Test 3 to 8' . PHP_EOL; echo '---------------------------------' . PHP_EOL; foreach (range(-10, 10) as $i) { echo $i . ' → ' . repeatInt($i, 3, 8) . PHP_EOL; } echo PHP_EOL; echo 'Test -2 to -4' . PHP_EOL; echo '---------------------------------' . PHP_EOL; foreach (range(-10, 10) as $i) { echo $i . ' → ' . repeatInt($i, -4, -2) . PHP_EOL; } echo PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 38
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 58
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 58
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 38
Branch analysis from position: 18
filename:       /in/Z9QXa
function name:  (null)
number of ops:  61
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ECHO                                                     'Test+2+to+5%0A'
   16     1        ECHO                                                     '---------------------------------%0A'
   17     2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 -10
          4        SEND_VAL                                                 10
          5        DO_ICALL                                         $1      
          6      > FE_RESET_R                                       $2      $1, ->18
          7    > > FE_FETCH_R                                               $2, !0, ->18
   19     8    >   CONCAT                                           ~3      !0, '+%E2%86%92+'
          9        INIT_FCALL                                               'repeatint'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 2
         12        SEND_VAL                                                 5
         13        DO_FCALL                                      0  $4      
         14        CONCAT                                           ~5      ~3, $4
         15        CONCAT                                           ~6      ~5, '%0A'
         16        ECHO                                                     ~6
   17    17      > JMP                                                      ->7
         18    >   FE_FREE                                                  $2
   21    19        ECHO                                                     '%0A'
   23    20        ECHO                                                     'Test+3+to+8%0A'
   24    21        ECHO                                                     '---------------------------------%0A'
   25    22        INIT_FCALL                                               'range'
         23        SEND_VAL                                                 -10
         24        SEND_VAL                                                 10
         25        DO_ICALL                                         $7      
         26      > FE_RESET_R                                       $8      $7, ->38
         27    > > FE_FETCH_R                                               $8, !0, ->38
   27    28    >   CONCAT                                           ~9      !0, '+%E2%86%92+'
         29        INIT_FCALL                                               'repeatint'
         30        SEND_VAR                                                 !0
         31        SEND_VAL                                                 3
         32        SEND_VAL                                                 8
         33        DO_FCALL                                      0  $10     
         34        CONCAT                                           ~11     ~9, $10
         35        CONCAT                                           ~12     ~11, '%0A'
         36        ECHO                                                     ~12
   25    37      > JMP                                                      ->27
         38    >   FE_FREE                                                  $8
   29    39        ECHO                                                     '%0A'
   31    40        ECHO                                                     'Test+-2+to+-4%0A'
   32    41        ECHO                                                     '---------------------------------%0A'
   33    42        INIT_FCALL                                               'range'
         43        SEND_VAL                                                 -10
         44        SEND_VAL                                                 10
         45        DO_ICALL                                         $13     
         46      > FE_RESET_R                                       $14     $13, ->58
         47    > > FE_FETCH_R                                               $14, !0, ->58
   35    48    >   CONCAT                                           ~15     !0, '+%E2%86%92+'
         49        INIT_FCALL                                               'repeatint'
         50        SEND_VAR                                                 !0
         51        SEND_VAL                                                 -4
         52        SEND_VAL                                                 -2
         53        DO_FCALL                                      0  $16     
         54        CONCAT                                           ~17     ~15, $16
         55        CONCAT                                           ~18     ~17, '%0A'
         56        ECHO                                                     ~18
   33    57      > JMP                                                      ->47
         58    >   FE_FREE                                                  $14
   37    59        ECHO                                                     '%0A'
   38    60      > RETURN                                                   1

Function repeatint:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/Z9QXa
function name:  repeatInt
number of ops:  16
compiled vars:  !0 = $val, !1 = $min, !2 = $max, !3 = $listLength, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        SUB                                              ~5      !2, !1
          4        ADD                                              ~6      ~5, 1
          5        ASSIGN                                                   !3, ~6
    6     6        MOD                                              ~8      !0, !3
          7        MOD                                              ~9      ~8, !3
          8        ASSIGN                                                   !4, ~9
    8     9        IS_SMALLER                                               !4, 0
         10      > JMPZ                                                     ~11, ->14
    9    11    >   MOD                                              ~12     !4, !3
         12        ADD                                              ~13     !3, ~12
         13        ASSIGN                                                   !4, ~13
   12    14    > > RETURN                                                   !4
   13    15*     > RETURN                                                   null

End of function repeatint

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.06 ms | 1407 KiB | 18 Q