3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = []; $keys = '[a][b][c]'; $value = 'HELLO WORLD'; function setArrayValueFromKeys(&$array, $keys, $value) { $keys = explode('][', trim($keys, '[]')); $reference = &$array; foreach ($keys as $key) { if (!array_key_exists($key, $reference)) { $reference[$key] = []; } $reference = &$reference[$key]; } $reference = $value; } setArrayValueFromKeys($array, $keys, $value); var_dump($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vBpEj
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array, !1 = $keys, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, '%5Ba%5D%5Bb%5D%5Bc%5D'
    5     2        ASSIGN                                                   !2, 'HELLO+WORLD'
   20     3        INIT_FCALL                                               'setarrayvaluefromkeys'
          4        SEND_REF                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0          
   21     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function setarrayvaluefromkeys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 20
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/vBpEj
function name:  setArrayValueFromKeys
number of ops:  26
compiled vars:  !0 = $array, !1 = $keys, !2 = $value, !3 = $reference, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    9     3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '%5D%5B'
          5        INIT_FCALL                                               'trim'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 '%5B%5D'
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !1, $6
   10    12        ASSIGN_REF                                               !3, !0
   11    13      > FE_RESET_R                                       $9      !1, ->23
         14    > > FE_FETCH_R                                               $9, !4, ->23
   12    15    >   ARRAY_KEY_EXISTS                                 ~10     !4, !3
         16        BOOL_NOT                                         ~11     ~10
         17      > JMPZ                                                     ~11, ->20
   13    18    >   ASSIGN_DIM                                               !3, !4
         19        OP_DATA                                                  <array>
   15    20    >   FETCH_DIM_W                                      $13     !3, !4
         21        ASSIGN_REF                                               !3, $13
   11    22      > JMP                                                      ->14
         23    >   FE_FREE                                                  $9
   17    24        ASSIGN                                                   !3, !2
   18    25      > RETURN                                                   null

End of function setarrayvaluefromkeys

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.57 ms | 994 KiB | 17 Q