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] = array(); $_init[$key] = $add; return [ $key => array_merge($_init[$key], $init[$key]) ]; } } $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, 'full'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iMvcB
function name:  (null)
number of ops:  30
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   24     1        ASSIGN                                                   !1, <array>
   28     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                                                 
   31    10        ASSIGN                                                   !0, <array>
   34    11        ASSIGN                                                   !1, <array>
   38    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                                                 
   41    19        ASSIGN                                                   !0, <array>
   46    20        ASSIGN                                                   !1, <array>
   50    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'append'
         23        SEND_VAR                                                 !0
         24        SEND_VAR                                                 !1
         25        SEND_VAL                                                 'full'
         26        DO_FCALL                                      0  $12     
         27        SEND_VAR                                                 $12
         28        DO_ICALL                                                 
         29      > 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 = 23
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/iMvcB
function name:  append
number of ops:  34
compiled vars:  !0 = $init, !1 = $add, !2 = $key, !3 = $initialKeyExist, !4 = $_init, !5 = $value
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                                                     ~7, ->20
    6     7    > > FE_RESET_R                                       $8      !1, ->13
          8    > > FE_FETCH_R                                       ~9      $8, !5, ->13
          9    >   ASSIGN                                                   !2, ~9
    7    10        ASSIGN_DIM                                               !4, !2
         11        OP_DATA                                                  !5
    6    12      > JMP                                                      ->8
         13    >   FE_FREE                                                  $8
    8    14        INIT_FCALL                                               'array_merge'
         15        SEND_VAR                                                 !4
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $12     
         18      > RETURN                                                   $12
         19*       JMP                                                      ->33
   10    20    > > JMPZ                                                     !3, ->23
   11    21    >   ASSIGN_DIM                                               !0, !2
         22        OP_DATA                                                  <array>
   12    23    >   ASSIGN_DIM                                               !4, !2
         24        OP_DATA                                                  !1
   14    25        INIT_FCALL                                               'array_merge'
         26        FETCH_DIM_R                                      ~15     !4, !2
         27        SEND_VAL                                                 ~15
         28        FETCH_DIM_R                                      ~16     !0, !2
         29        SEND_VAL                                                 ~16
         30        DO_ICALL                                         $17     
         31        INIT_ARRAY                                       ~18     $17, !2
         32      > RETURN                                                   ~18
   17    33*     > RETURN                                                   null

End of function append

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.11 ms | 1394 KiB | 20 Q