3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = [ 'fruits' => [ 'apple' => 'red', 'banana' => 'yellow' ], 'numbers' => [1, 2] ]; $array2 = [ 'fruits' => [ 'orange' => 'orange', 'apple' => 'green' // Should overwrite 'red' ], ]; $array3 = [ 'numbers' => [2, 3, 4], // Should extend, not replace 'colors' => ['blue', 'purple'] // New key should be added ]; function mergeNestedArraysInefficient(array $array, array ...$otherArrays) { foreach ($otherArrays as $other) { if (array_is_list($other)) { $array = array_values(array_unique(array_merge($array, $other))); continue; } foreach ($other as $k => $v) { if (is_array($v) && key_exists($k, $array)) { $array[$k] = mergeNestedArraysInefficient($array[$k], $v); } else { $array[$k] = $v; } } } return $array; } var_export(mergeNestedArraysInefficient($array1, $array2, $array3));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8a37r
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array1, !1 = $array2, !2 = $array3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, <array>
   41     3        INIT_FCALL                                               'var_export'
          4        INIT_FCALL                                               'mergenestedarraysinefficient'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !2
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR                                                 $6
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function mergenestedarraysinefficient:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 45
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 45
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 43
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 43
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 40
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 30
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 43
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/8a37r
function name:  mergeNestedArraysInefficient
number of ops:  48
compiled vars:  !0 = $array, !1 = $otherArrays, !2 = $other, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
   24     2      > FE_RESET_R                                       $5      !1, ->45
          3    > > FE_FETCH_R                                               $5, !2, ->45
   25     4    >   INIT_FCALL                                               'array_is_list'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $6      
          7      > JMPZ                                                     $6, ->20
   26     8    >   INIT_FCALL                                               'array_values'
          9        INIT_FCALL                                               'array_unique'
         10        INIT_FCALL                                               'array_merge'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $7      
         14        SEND_VAR                                                 $7
         15        DO_ICALL                                         $8      
         16        SEND_VAR                                                 $8
         17        DO_ICALL                                         $9      
         18        ASSIGN                                                   !0, $9
   27    19      > JMP                                                      ->3
   29    20    > > FE_RESET_R                                       $11     !2, ->43
         21    > > FE_FETCH_R                                       ~12     $11, !3, ->43
         22    >   ASSIGN                                                   !4, ~12
   30    23        TYPE_CHECK                                  128  ~14     !3
         24      > JMPZ_EX                                          ~14     ~14, ->30
         25    >   INIT_FCALL                                               'key_exists'
         26        SEND_VAR                                                 !4
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $15     
         29        BOOL                                             ~14     $15
         30    > > JMPZ                                                     ~14, ->40
   31    31    >   INIT_FCALL_BY_NAME                                       'mergeNestedArraysInefficient'
         32        CHECK_FUNC_ARG                                           
         33        FETCH_DIM_FUNC_ARG                               $17     !0, !4
         34        SEND_FUNC_ARG                                            $17
         35        SEND_VAR_EX                                              !3
         36        DO_FCALL                                      0  $18     
         37        ASSIGN_DIM                                               !0, !4
         38        OP_DATA                                                  $18
   30    39      > JMP                                                      ->42
   33    40    >   ASSIGN_DIM                                               !0, !4
         41        OP_DATA                                                  !3
   29    42    > > JMP                                                      ->21
         43    >   FE_FREE                                                  $11
   24    44      > JMP                                                      ->3
         45    >   FE_FREE                                                  $5
   38    46      > RETURN                                                   !0
   39    47*     > RETURN                                                   null

End of function mergenestedarraysinefficient

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.16 ms | 1080 KiB | 20 Q