3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'a', 'b', 'c', ]; function insertWhileIteratingForward($arr) { foreach ($arr as $index => $value) { if ($value === 'a' || $value === 'c') { array_splice($arr, $index, 0, ['new', 'new', 'new', 'new', 'new']); } } return $arr; } function insertWhileIteratingBackward($arr) { for ($index = count($arr) - 1; $index >= 0; --$index) { $value = $arr[$index]; if ($value === 'a' || $value === 'c') { array_splice($arr, $index, 0, ['new', 'new', 'new', 'new', 'new']); } } return $arr; } var_dump(insertWhileIteratingForward($array)); var_dump(insertWhileIteratingBackward($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sP9s0
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   32     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'insertwhileiteratingforward'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   33     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'insertwhileiteratingbackward'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function insertwhileiteratingforward:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 16
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 15
Branch analysis from position: 8
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/sP9s0
function name:  insertWhileIteratingForward
number of ops:  19
compiled vars:  !0 = $arr, !1 = $value, !2 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1      > FE_RESET_R                                       $3      !0, ->16
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->16
          3    >   ASSIGN                                                   !2, ~4
   11     4        IS_IDENTICAL                                     ~6      !1, 'a'
          5      > JMPNZ_EX                                         ~6      ~6, ->8
          6    >   IS_IDENTICAL                                     ~7      !1, 'c'
          7        BOOL                                             ~6      ~7
          8    > > JMPZ                                                     ~6, ->15
   12     9    >   INIT_FCALL                                               'array_splice'
         10        SEND_REF                                                 !0
         11        SEND_VAR                                                 !2
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 <array>
         14        DO_ICALL                                                 
   10    15    > > JMP                                                      ->2
         16    >   FE_FREE                                                  $3
   16    17      > RETURN                                                   !0
   17    18*     > RETURN                                                   null

End of function insertwhileiteratingforward

Function insertwhileiteratingbackward:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
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 = 18
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 5
Branch analysis from position: 21
Branch analysis from position: 5
Branch analysis from position: 18
Branch analysis from position: 11
filename:       /in/sP9s0
function name:  insertWhileIteratingBackward
number of ops:  23
compiled vars:  !0 = $arr, !1 = $index, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        COUNT                                            ~3      !0
          2        SUB                                              ~4      ~3, 1
          3        ASSIGN                                                   !1, ~4
          4      > JMP                                                      ->19
   21     5    >   FETCH_DIM_R                                      ~6      !0, !1
          6        ASSIGN                                                   !2, ~6
   23     7        IS_IDENTICAL                                     ~8      !2, 'a'
          8      > JMPNZ_EX                                         ~8      ~8, ->11
          9    >   IS_IDENTICAL                                     ~9      !2, 'c'
         10        BOOL                                             ~8      ~9
         11    > > JMPZ                                                     ~8, ->18
   24    12    >   INIT_FCALL                                               'array_splice'
         13        SEND_REF                                                 !0
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 0
         16        SEND_VAL                                                 <array>
         17        DO_ICALL                                                 
   20    18    >   PRE_DEC                                                  !1
         19    >   IS_SMALLER_OR_EQUAL                                      0, !1
         20      > JMPNZ                                                    ~12, ->5
   28    21    > > RETURN                                                   !0
   29    22*     > RETURN                                                   null

End of function insertwhileiteratingbackward

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.82 ms | 1019 KiB | 17 Q