3v4l.org

run code in 500+ PHP versions simultaneously
<?php $a = [0, 1, 2, 3, 4, 5, 6, 7]; $index = 3; // Result: 1, 2, 3, 4, 5. *example 1 echo pages($a, $index) . "\n"; $index = 0; // Result: 0, 1, 2, 3, 4. *example 2 echo pages($a, $index) . "\n"; $index = 7; // Result: 3, 4, 5, 6, 7. *example 3 echo pages($a, $index) . "\n"; $index = 6; // Result: 3, 4, 5, 6, 7. *example 4 echo pages($a, $index) . "\n"; function pages($a, $index){ if($index >= count($a)-2){ $start = count($a)-5; }elseif($index <=2){ $start = 0; }else{ $start = $index-2; } return implode(", ", array_slice($a, $start, 5)); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNZsB
function name:  (null)
number of ops:  30
compiled vars:  !0 = $a, !1 = $index
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    6     1        ASSIGN                                                       !1, 3
    7     2        INIT_FCALL_BY_NAME                                           'pages'
          3        SEND_VAR_EX                                                  !0
          4        SEND_VAR_EX                                                  !1
          5        DO_FCALL                                          0  $4      
          6        CONCAT                                               ~5      $4, '%0A'
          7        ECHO                                                         ~5
   10     8        ASSIGN                                                       !1, 0
   11     9        INIT_FCALL_BY_NAME                                           'pages'
         10        SEND_VAR_EX                                                  !0
         11        SEND_VAR_EX                                                  !1
         12        DO_FCALL                                          0  $7      
         13        CONCAT                                               ~8      $7, '%0A'
         14        ECHO                                                         ~8
   14    15        ASSIGN                                                       !1, 7
   15    16        INIT_FCALL_BY_NAME                                           'pages'
         17        SEND_VAR_EX                                                  !0
         18        SEND_VAR_EX                                                  !1
         19        DO_FCALL                                          0  $10     
         20        CONCAT                                               ~11     $10, '%0A'
         21        ECHO                                                         ~11
   18    22        ASSIGN                                                       !1, 6
   19    23        INIT_FCALL_BY_NAME                                           'pages'
         24        SEND_VAR_EX                                                  !0
         25        SEND_VAR_EX                                                  !1
         26        DO_FCALL                                          0  $13     
         27        CONCAT                                               ~14     $13, '%0A'
         28        ECHO                                                         ~14
   33    29      > RETURN                                                       1

Function pages:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNZsB
function name:  pages
number of ops:  24
compiled vars:  !0 = $a, !1 = $index, !2 = $start
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   24     2        COUNT                                                ~3      !0
          3        SUB                                                  ~4      ~3, 2
          4        IS_SMALLER_OR_EQUAL                                          ~4, !1
          5      > JMPZ                                                         ~5, ->10
   25     6    >   COUNT                                                ~6      !0
          7        SUB                                                  ~7      ~6, 5
          8        ASSIGN                                                       !2, ~7
   24     9      > JMP                                                          ->16
   26    10    >   IS_SMALLER_OR_EQUAL                                          !1, 2
         11      > JMPZ                                                         ~9, ->14
   27    12    >   ASSIGN                                                       !2, 0
   26    13      > JMP                                                          ->16
   29    14    >   SUB                                                  ~11     !1, 2
         15        ASSIGN                                                       !2, ~11
   31    16    >   INIT_FCALL                                                   'array_slice'
         17        SEND_VAR                                                     !0
         18        SEND_VAR                                                     !2
         19        SEND_VAL                                                     5
         20        DO_ICALL                                             $13     
         21        FRAMELESS_ICALL_2                implode             ~14     '%2C+', $13
         22      > RETURN                                                       ~14
   33    23*     > RETURN                                                       null

End of function pages

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
220.13 ms | 2114 KiB | 14 Q