3v4l.org

run code in 300+ PHP versions simultaneously
<?php function initValueIfNotSet($target, $levels = array()) { //$merge = ['WorkRecord' => ['Hours' => '']]; $merge = []; for ($i = count($levels) - 1; $i >= 0; $i--) { $current = $levels[$i]; $merge = empty($merge) ? [$current => ''] : [$current => $merge]; } //return $target + $merge; return array_merge_recursive($target, $merge); } $user = ['Details' => ['Name' => 'Kokot'], 'WorkRecord' => ['Time' => ['Minutes' => 2]]]; var_dump($user); $user = initValueIfNotSet($user, ['WorkRecord', 'Time', 'Hours']); var_dump($user);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MRQV7
function name:  (null)
number of ops:  13
compiled vars:  !0 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, <array>
   17     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   19     4        INIT_FCALL                                               'initvalueifnotset'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 <array>
          7        DO_FCALL                                      0  $3      
          8        ASSIGN                                                   !0, $3
   21     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function initvalueifnotset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 7
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 7
Branch analysis from position: 20
Branch analysis from position: 7
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 7
Branch analysis from position: 20
Branch analysis from position: 7
filename:       /in/MRQV7
function name:  initValueIfNotSet
number of ops:  26
compiled vars:  !0 = $target, !1 = $levels, !2 = $merge, !3 = $i, !4 = $current
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3        COUNT                                            ~6      !1
          4        SUB                                              ~7      ~6, 1
          5        ASSIGN                                                   !3, ~7
          6      > JMP                                                      ->18
    7     7    >   FETCH_DIM_R                                      ~9      !1, !3
          8        ASSIGN                                                   !4, ~9
    8     9        ISSET_ISEMPTY_CV                                         !2
         10      > JMPZ                                                     ~11, ->14
         11    >   INIT_ARRAY                                       ~12     '', !4
         12        QM_ASSIGN                                        ~13     ~12
         13      > JMP                                                      ->16
         14    >   INIT_ARRAY                                       ~14     !2, !4
         15        QM_ASSIGN                                        ~13     ~14
         16    >   ASSIGN                                                   !2, ~13
    6    17        PRE_DEC                                                  !3
         18    >   IS_SMALLER_OR_EQUAL                                      0, !3
         19      > JMPNZ                                                    ~17, ->7
   12    20    >   INIT_FCALL                                               'array_merge_recursive'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $18     
         24      > RETURN                                                   $18
   13    25*     > RETURN                                                   null

End of function initvalueifnotset

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.55 ms | 1403 KiB | 18 Q