3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = ["split", "cat", "split", "dog", "cow"]; $rebuild = []; $offset = 0; foreach ($arr as $key => $value) { if ($value === 'split') { $rebuild = array_filter([...$rebuild, array_slice($arr, $offset, $key - $offset)]); $offset = ++$key; } } var_dump([...$rebuild, array_slice($arr, $offset, count($arr) - $offset)]);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/oloD0
function name:  (null)
number of ops:  39
compiled vars:  !0 = $arr, !1 = $rebuild, !2 = $offset, !3 = $value, !4 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    4     1        ASSIGN                                                       !1, <array>
    5     2        ASSIGN                                                       !2, 0
    7     3      > FE_RESET_R                                           $8      !0, ->24
          4    > > FE_FETCH_R                                           ~9      $8, !3, ->24
          5    >   ASSIGN                                                       !4, ~9
    8     6        IS_IDENTICAL                                                 !3, 'split'
          7      > JMPZ                                                         ~11, ->23
    9     8    >   INIT_FCALL                                                   'array_filter'
          9        INIT_ARRAY                                           ~12     
         10        ADD_ARRAY_UNPACK                                     ~12     !1
         11        INIT_FCALL                                                   'array_slice'
         12        SEND_VAR                                                     !0
         13        SEND_VAR                                                     !2
         14        SUB                                                  ~13     !4, !2
         15        SEND_VAL                                                     ~13
         16        DO_ICALL                                             $14     
         17        ADD_ARRAY_ELEMENT                                    ~12     $14
         18        SEND_VAL                                                     ~12
         19        DO_ICALL                                             $15     
         20        ASSIGN                                                       !1, $15
   10    21        PRE_INC                                              ~17     !4
         22        ASSIGN                                                       !2, ~17
    7    23    > > JMP                                                          ->4
         24    >   FE_FREE                                                      $8
   14    25        INIT_FCALL                                                   'var_dump'
         26        INIT_ARRAY                                           ~19     
         27        ADD_ARRAY_UNPACK                                     ~19     !1
         28        INIT_FCALL                                                   'array_slice'
         29        SEND_VAR                                                     !0
         30        SEND_VAR                                                     !2
         31        COUNT                                                ~20     !0
         32        SUB                                                  ~21     ~20, !2
         33        SEND_VAL                                                     ~21
         34        DO_ICALL                                             $22     
         35        ADD_ARRAY_ELEMENT                                    ~19     $22
         36        SEND_VAL                                                     ~19
         37        DO_ICALL                                                     
         38      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.98 ms | 1914 KiB | 16 Q