3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = ["test1", "test2"]; $tree = array( 10 => array(), 11 => array( 4 => array(), 5 => array(), 6 => array() ) ); $path = array(11,5); function setByIndices(&$tree, $path, $data, $indices = []) { foreach ($tree as $k => &$v) { $indices[] = $k; if ($indices === $path) { $v = $data; return; } if (is_array($v)) setByIndices($v, $path, $data, $indices); array_pop($indices); } } setByIndices($tree, $path, $data); print_r($tree);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aIoe6
function name:  (null)
number of ops:  12
compiled vars:  !0 = $data, !1 = $tree, !2 = $path
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    4     1        ASSIGN                                                       !1, <array>
   13     2        ASSIGN                                                       !2, <array>
   27     3        INIT_FCALL                                                   'setbyindices'
          4        SEND_REF                                                     !1
          5        SEND_VAR                                                     !2
          6        SEND_VAR                                                     !0
          7        DO_FCALL                                          0          
   29     8        INIT_FCALL                                                   'print_r'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
         11      > RETURN                                                       1

Function setbyindices:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 126) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 22
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/aIoe6
function name:  setByIndices
number of ops:  28
compiled vars:  !0 = $tree, !1 = $path, !2 = $data, !3 = $indices, !4 = $v, !5 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
          3        RECV_INIT                                            !3      <array>
   16     4      > FE_RESET_RW                                          $6      !0, ->26
          5    > > FE_FETCH_RW                                          ~7      $6, !4, ->26
          6    >   ASSIGN                                                       !5, ~7
   17     7        ASSIGN_DIM                                                   !3
          8        OP_DATA                                                      !5
   18     9        IS_IDENTICAL                                                 !3, !1
         10      > JMPZ                                                         ~10, ->14
   19    11    >   ASSIGN                                                       !4, !2
   20    12        FE_FREE                                                      $6
         13      > RETURN                                                       null
   22    14    >   TYPE_CHECK                                      128          !4
         15      > JMPZ                                                         ~12, ->22
         16    >   INIT_FCALL_BY_NAME                                           'setByIndices'
         17        SEND_VAR_EX                                                  !4
         18        SEND_VAR_EX                                                  !1
         19        SEND_VAR_EX                                                  !2
         20        SEND_VAR_EX                                                  !3
         21        DO_FCALL                                          0          
   23    22    >   INIT_FCALL                                                   'array_pop'
         23        SEND_REF                                                     !3
         24        DO_ICALL                                                     
   16    25      > JMP                                                          ->5
         26    >   FE_FREE                                                      $6
   25    27      > RETURN                                                       null

End of function setbyindices

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
127.07 ms | 486 KiB | 10 Q