3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ['one', 'two', 'three', 'four', 'five']; echo 'foreach on $arr' . PHP_EOL; foreach($arr as $elem) { var_dump(current($arr)); } echo PHP_EOL . 'foreach on $refArr' . PHP_EOL; $refArr = &$arr; foreach($refArr as $elem) { var_dump(current($arr)); } echo 'substituting array during iteration' . PHP_EOL; $refArr = &$arr; foreach($refArr as $elem) { if ($elem == 'three') { $arr = [1, 2, 3, 4, 5]; } echo $elem . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 31
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 23
Branch analysis from position: 11
filename:       /in/TNPNb
function name:  (null)
number of ops:  36
compiled vars:  !0 = $arr, !1 = $elem, !2 = $refArr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ECHO                                                     'foreach+on+%24arr%0A'
    6     2      > FE_RESET_R                                       $4      !0, ->11
          3    > > FE_FETCH_R                                               $4, !1, ->11
    7     4    >   INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'current'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $5      
          8        SEND_VAR                                                 $5
          9        DO_ICALL                                                 
    6    10      > JMP                                                      ->3
         11    >   FE_FREE                                                  $4
   10    12        ECHO                                                     '%0Aforeach+on+%24refArr%0A'
   11    13        ASSIGN_REF                                               !2, !0
   12    14      > FE_RESET_R                                       $8      !2, ->23
         15    > > FE_FETCH_R                                               $8, !1, ->23
   13    16    >   INIT_FCALL                                               'var_dump'
         17        INIT_FCALL                                               'current'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $9      
         20        SEND_VAR                                                 $9
         21        DO_ICALL                                                 
   12    22      > JMP                                                      ->15
         23    >   FE_FREE                                                  $8
   16    24        ECHO                                                     'substituting+array+during+iteration%0A'
   18    25        ASSIGN_REF                                               !2, !0
   19    26      > FE_RESET_R                                       $12     !2, ->34
         27    > > FE_FETCH_R                                               $12, !1, ->34
   20    28    >   IS_EQUAL                                                 !1, 'three'
         29      > JMPZ                                                     ~13, ->31
   21    30    >   ASSIGN                                                   !0, <array>
   23    31    >   CONCAT                                           ~15     !1, '%0A'
         32        ECHO                                                     ~15
   19    33      > JMP                                                      ->27
         34    >   FE_FREE                                                  $12
   24    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.1 ms | 1405 KiB | 17 Q