3v4l.org

run code in 500+ PHP versions simultaneously
<?php $collection = [ 'A', 'B', 'C', 'D', 'E' ]; $offset = 4; $limit = 2; If($offset>count($collection) || $offset < 0 || $limit ==0) die("inputs out of bounds"); If($offset-$limit >=0){ $start = $offset-$limit; }else{ $start =0; } If($offset+$limit>count($collection)){ $end = count($collection)-$offset+$limit; }else{ $end = $offset + $limit; } If($start ==0) $end++; $result = array_slice($collection, $start, $end); Var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
Branch analysis from position: 36
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
Branch analysis from position: 31
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/0l1J6
function name:  (null)
number of ops:  46
compiled vars:  !0 = $collection, !1 = $offset, !2 = $limit, !3 = $start, !4 = $end, !5 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    4     1        ASSIGN                                                       !1, 4
    5     2        ASSIGN                                                       !2, 2
    7     3        COUNT                                                ~9      !0
          4        IS_SMALLER                                           ~10     ~9, !1
          5      > JMPNZ_EX                                             ~10     ~10, ->8
          6    >   IS_SMALLER                                           ~11     !1, 0
          7        BOOL                                                 ~10     ~11
          8    > > JMPNZ_EX                                             ~10     ~10, ->11
          9    >   IS_EQUAL                                             ~12     !2, 0
         10        BOOL                                                 ~10     ~12
         11    > > JMPZ                                                         ~10, ->15
         12    > > INIT_FCALL                                                   'exit'
         13*       SEND_VAL                                                     'inputs+out+of+bounds'
         14*       DO_ICALL                                                     
   10    15    >   SUB                                                  ~14     !1, !2
         16        IS_SMALLER_OR_EQUAL                                          0, ~14
         17      > JMPZ                                                         ~15, ->21
   11    18    >   SUB                                                  ~16     !1, !2
         19        ASSIGN                                                       !3, ~16
   10    20      > JMP                                                          ->22
   13    21    >   ASSIGN                                                       !3, 0
   16    22    >   ADD                                                  ~19     !1, !2
         23        COUNT                                                ~20     !0
         24        IS_SMALLER                                                   ~20, ~19
         25      > JMPZ                                                         ~21, ->31
   17    26    >   COUNT                                                ~22     !0
         27        SUB                                                  ~23     ~22, !1
         28        ADD                                                  ~24     ~23, !2
         29        ASSIGN                                                       !4, ~24
   16    30      > JMP                                                          ->33
   19    31    >   ADD                                                  ~26     !1, !2
         32        ASSIGN                                                       !4, ~26
   21    33    >   IS_EQUAL                                                     !3, 0
         34      > JMPZ                                                         ~28, ->36
         35    >   PRE_INC                                                      !4
   23    36    >   INIT_FCALL                                                   'array_slice'
         37        SEND_VAR                                                     !0
         38        SEND_VAR                                                     !3
         39        SEND_VAR                                                     !4
         40        DO_ICALL                                             $30     
         41        ASSIGN                                                       !5, $30
   24    42        INIT_FCALL                                                   'var_dump'
         43        SEND_VAR                                                     !5
         44        DO_ICALL                                                     
         45      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
230.81 ms | 2272 KiB | 16 Q