3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [0, 1, 2]; $ref =& $array; // Necessary to trigger the old behavior $i = 0; foreach ($array as $k => &$val) { $i++; echo $i . ':' . $k . ':' . $val . ' '; if($i < 5 && !isset($array[$i])) $array[$i] = $val+1; if($i == 2) array_unshift($array, 'X'); } echo PHP_EOL . json_encode($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
2 jumps found. (Code = 126) Position 1 = 5, Position 2 = 29
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 28
Branch analysis from position: 22
Branch analysis from position: 18
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/nj9sE
function name:  (null)
number of ops:  36
compiled vars:  !0 = $array, !1 = $ref, !2 = $i, !3 = $val, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN_REF                                               !1, !0
    5     2        ASSIGN                                                   !2, 0
    6     3      > FE_RESET_RW                                      $8      !0, ->29
          4    > > FE_FETCH_RW                                      ~9      $8, !3, ->29
          5    >   ASSIGN                                                   !4, ~9
    7     6        PRE_INC                                                  !2
    8     7        CONCAT                                           ~12     !2, '%3A'
          8        CONCAT                                           ~13     ~12, !4
          9        CONCAT                                           ~14     ~13, '%3A'
         10        CONCAT                                           ~15     ~14, !3
         11        CONCAT                                           ~16     ~15, '+'
         12        ECHO                                                     ~16
    9    13        IS_SMALLER                                       ~17     !2, 5
         14      > JMPZ_EX                                          ~17     ~17, ->18
         15    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !0, !2
         16        BOOL_NOT                                         ~19     ~18
         17        BOOL                                             ~17     ~19
         18    > > JMPZ                                                     ~17, ->22
         19    >   ADD                                              ~21     !3, 1
         20        ASSIGN_DIM                                               !0, !2
         21        OP_DATA                                                  ~21
   10    22    >   IS_EQUAL                                                 !2, 2
         23      > JMPZ                                                     ~22, ->28
         24    >   INIT_FCALL                                               'array_unshift'
         25        SEND_REF                                                 !0
         26        SEND_VAL                                                 'X'
         27        DO_ICALL                                                 
    6    28    > > JMP                                                      ->4
         29    >   FE_FREE                                                  $8
   12    30        INIT_FCALL                                               'json_encode'
         31        SEND_VAR                                                 !0
         32        DO_ICALL                                         $24     
         33        CONCAT                                           ~25     '%0A', $24
         34        ECHO                                                     ~25
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.87 ms | 1400 KiB | 17 Q