3v4l.org

run code in 300+ PHP versions simultaneously
<?php function append(array $init, array $add, $key = null, $initialKeyExist = true) { $_init = $init; if (is_null($key)) { foreach ($add as $key => $value) $_init[$key] = $value; return array_merge($_init, $init); } else { if ($initialKeyExist) { $_init[$key] = $add; return [ $key => array_merge($_init[$key], $init[$key]) ]; } else { foreach ($add as $k => $value) $_init[$key][$k] = $value; return $_init; } } } $a = [ 'phone' => [ 'code' => '+38', ], ]; $b = [ 'prefix' => '095', 'number' => '7700418', ]; var_dump(append($a, $b, 'phone')); $a = [ 'code' => '+38', ]; $b = [ 'prefix' => '095', 'number' => '7700418', ]; var_dump(append($a, $b)); $a = [ 'phone' => [ 'code' => '+38', ], ]; $b = [ 'prefix' => '095', 'number' => '7700418', ]; var_dump(append($a, $b, 'phone', false));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MZgku
function name:  (null)
number of ops:  31
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   28     1        ASSIGN                                                   !1, <array>
   32     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'append'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 'phone'
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                                 
   35    10        ASSIGN                                                   !0, <array>
   38    11        ASSIGN                                                   !1, <array>
   42    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'append'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR                                                 $8
         18        DO_ICALL                                                 
   45    19        ASSIGN                                                   !0, <array>
   50    20        ASSIGN                                                   !1, <array>
   54    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'append'
         23        SEND_VAR                                                 !0
         24        SEND_VAR                                                 !1
         25        SEND_VAL                                                 'phone'
         26        SEND_VAL                                                 <false>
         27        DO_FCALL                                      0  $12     
         28        SEND_VAR                                                 $12
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Function append:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 32
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 39
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/MZgku
function name:  append
number of ops:  42
compiled vars:  !0 = $init, !1 = $add, !2 = $key, !3 = $initialKeyExist, !4 = $_init, !5 = $value, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
          3        RECV_INIT                                        !3      <true>
    4     4        ASSIGN                                                   !4, !0
    5     5        TYPE_CHECK                                    2          !2
          6      > JMPZ                                                     ~8, ->20
    6     7    > > FE_RESET_R                                       $9      !1, ->13
          8    > > FE_FETCH_R                                       ~10     $9, !5, ->13
          9    >   ASSIGN                                                   !2, ~10
    7    10        ASSIGN_DIM                                               !4, !2
         11        OP_DATA                                                  !5
    6    12      > JMP                                                      ->8
         13    >   FE_FREE                                                  $9
    8    14        INIT_FCALL                                               'array_merge'
         15        SEND_VAR                                                 !4
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $13     
         18      > RETURN                                                   $13
         19*       JMP                                                      ->41
   10    20    > > JMPZ                                                     !3, ->32
   11    21    >   ASSIGN_DIM                                               !4, !2
         22        OP_DATA                                                  !1
   13    23        INIT_FCALL                                               'array_merge'
         24        FETCH_DIM_R                                      ~15     !4, !2
         25        SEND_VAL                                                 ~15
         26        FETCH_DIM_R                                      ~16     !0, !2
         27        SEND_VAL                                                 ~16
         28        DO_ICALL                                         $17     
         29        INIT_ARRAY                                       ~18     $17, !2
         30      > RETURN                                                   ~18
         31*       JMP                                                      ->41
   16    32    > > FE_RESET_R                                       $19     !1, ->39
         33    > > FE_FETCH_R                                       ~20     $19, !5, ->39
         34    >   ASSIGN                                                   !6, ~20
   17    35        FETCH_DIM_W                                      $22     !4, !2
         36        ASSIGN_DIM                                               $22, !6
         37        OP_DATA                                                  !5
   16    38      > JMP                                                      ->33
         39    >   FE_FREE                                                  $19
   18    40      > RETURN                                                   !4
   21    41*     > RETURN                                                   null

End of function append

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
268.62 ms | 1402 KiB | 21 Q