3v4l.org

run code in 300+ PHP versions simultaneously
<?php function foo() { $reqs = array('11', '22', array('id' => 123, 'name' => 'ffff')); foreach ($reqs as &$req) { if (is_array($req)) { $req['name'] = 'dd'; //alter value } } echo '<pre>'; print_r($reqs); //values changed, ok echo '</pre>'; foreach ($reqs as $req) { echo '<pre>'; print_r($req); //the last value is '22', that is wrong. echo '</pre>'; } } foo();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CafJM
function name:  (null)
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'foo'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   1

Function foo:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 8
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 8
filename:       /in/CafJM
function name:  foo
number of ops:  24
compiled vars:  !0 = $reqs, !1 = $req
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1      > FE_RESET_RW                                      $3      !0, ->8
          2    > > FE_FETCH_RW                                              $3, !1, ->8
    5     3    >   TYPE_CHECK                                  128          !1
          4      > JMPZ                                                     ~4, ->7
    6     5    >   ASSIGN_DIM                                               !1, 'name'
          6        OP_DATA                                                  'dd'
    4     7    > > JMP                                                      ->2
          8    >   FE_FREE                                                  $3
    9     9        ECHO                                                     '%3Cpre%3E'
   10    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
   11    13        ECHO                                                     '%3C%2Fpre%3E'
   12    14      > FE_RESET_R                                       $7      !0, ->22
         15    > > FE_FETCH_R                                               $7, !1, ->22
   13    16    >   ECHO                                                     '%3Cpre%3E'
   14    17        INIT_FCALL                                               'print_r'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
   15    20        ECHO                                                     '%3C%2Fpre%3E'
   12    21      > JMP                                                      ->15
         22    >   FE_FREE                                                  $7
   17    23      > RETURN                                                   null

End of function foo

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.79 ms | 1403 KiB | 16 Q