3v4l.org

run code in 300+ PHP versions simultaneously
<?php function repeatIntMountain(int $value, int $min, int $max) { $validValueNum = $max - $min + 1; $offset = (($value % $validValueNum) + $min) % $validValueNum; return $min + $offset; } function repeatIntTuna(int $value, int $min, int $max) { $validValueNum = $max - $min + 1; $hogeX = $value + $min; if($value < 0){ $hogeX = 0 - $value + $min; } return ($hogeX % $validValueNum) + $min; } echo 'Test 2 to 5 (Mountain)' . PHP_EOL; echo '---------------------------------' . PHP_EOL; foreach (range(-10, 10) as $i) { echo $i . ' → ' . repeatIntMountain($i, 2, 5) . PHP_EOL; } echo PHP_EOL; echo 'Test 3 to 8 (Mountain)' . PHP_EOL; echo '---------------------------------' . PHP_EOL; foreach (range(-10, 10) as $i) { echo $i . ' → ' . repeatIntMountain($i, 3, 8) . PHP_EOL; } echo PHP_EOL; echo 'Test 2 to 5 (Tuna)' . PHP_EOL; echo '---------------------------------' . PHP_EOL; foreach (range(-10, 10) as $i) { echo $i . ' → ' . repeatIntTuna($i, 2, 5) . PHP_EOL; } echo PHP_EOL; echo 'Test 3 to 8 (Tuna)' . PHP_EOL; echo '---------------------------------' . PHP_EOL; foreach (range(-10, 10) as $i) { echo $i . ' → ' . repeatIntTuna($i, 3, 8) . 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
2 jumps found. (Code = 77) Position 1 = 67, Position 2 = 78
Branch analysis from position: 67
2 jumps found. (Code = 78) Position 1 = 68, Position 2 = 78
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
Branch analysis from position: 58
Branch analysis from position: 38
Branch analysis from position: 18
filename:       /in/fc3ab
function name:  (null)
number of ops:  81
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ECHO                                                     'Test+2+to+5+%28Mountain%29%0A'
   26     1        ECHO                                                     '---------------------------------%0A'
   27     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
   29     8    >   CONCAT                                           ~3      !0, '+%E2%86%92+'
          9        INIT_FCALL                                               'repeatintmountain'
         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
   27    17      > JMP                                                      ->7
         18    >   FE_FREE                                                  $2
   31    19        ECHO                                                     '%0A'
   33    20        ECHO                                                     'Test+3+to+8+%28Mountain%29%0A'
   34    21        ECHO                                                     '---------------------------------%0A'
   35    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
   37    28    >   CONCAT                                           ~9      !0, '+%E2%86%92+'
         29        INIT_FCALL                                               'repeatintmountain'
         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
   35    37      > JMP                                                      ->27
         38    >   FE_FREE                                                  $8
   39    39        ECHO                                                     '%0A'
   41    40        ECHO                                                     'Test+2+to+5+%28Tuna%29%0A'
   42    41        ECHO                                                     '---------------------------------%0A'
   43    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
   45    48    >   CONCAT                                           ~15     !0, '+%E2%86%92+'
         49        INIT_FCALL                                               'repeatinttuna'
         50        SEND_VAR                                                 !0
         51        SEND_VAL                                                 2
         52        SEND_VAL                                                 5
         53        DO_FCALL                                      0  $16     
         54        CONCAT                                           ~17     ~15, $16
         55        CONCAT                                           ~18     ~17, '%0A'
         56        ECHO                                                     ~18
   43    57      > JMP                                                      ->47
         58    >   FE_FREE                                                  $14
   47    59        ECHO                                                     '%0A'
   49    60        ECHO                                                     'Test+3+to+8+%28Tuna%29%0A'
   50    61        ECHO                                                     '---------------------------------%0A'
   51    62        INIT_FCALL                                               'range'
         63        SEND_VAL                                                 -10
         64        SEND_VAL                                                 10
         65        DO_ICALL                                         $19     
         66      > FE_RESET_R                                       $20     $19, ->78
         67    > > FE_FETCH_R                                               $20, !0, ->78
   53    68    >   CONCAT                                           ~21     !0, '+%E2%86%92+'
         69        INIT_FCALL                                               'repeatinttuna'
         70        SEND_VAR                                                 !0
         71        SEND_VAL                                                 3
         72        SEND_VAL                                                 8
         73        DO_FCALL                                      0  $22     
         74        CONCAT                                           ~23     ~21, $22
         75        CONCAT                                           ~24     ~23, '%0A'
         76        ECHO                                                     ~24
   51    77      > JMP                                                      ->67
         78    >   FE_FREE                                                  $20
   55    79        ECHO                                                     '%0A'
   56    80      > RETURN                                                   1

Function repeatintmountain:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fc3ab
function name:  repeatIntMountain
number of ops:  13
compiled vars:  !0 = $value, !1 = $min, !2 = $max, !3 = $validValueNum, !4 = $offset
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        ADD                                              ~9      ~8, !1
          8        MOD                                              ~10     ~9, !3
          9        ASSIGN                                                   !4, ~10
    8    10        ADD                                              ~12     !1, !4
         11      > RETURN                                                   ~12
    9    12*     > RETURN                                                   null

End of function repeatintmountain

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

End of function repeatinttuna

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.78 ms | 1407 KiB | 19 Q