3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arrayMergeRecursiveDistinct(array $first, array $second) { foreach ($second as $idx => $value) { if (is_integer($idx)) { $first[] = $value; } else { if (!array_key_exists($idx, $first)) { $first[$idx] = $value; } else { if (is_array($value)) { $first[$idx] = arrayMergeRecursiveDistinct($first[$idx], $value); } else { $first[$idx] = $value; } } } } return $first; } $a = ['a' => [1,2,3], 'b' => ['c' => ['d' => 'e']]]; $b = ['a' => [4,5,6], 'b']; print_r(arrayMergeRecursiveDistinct($b, $a)); print_r(array_replace_recursive($b, $a));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/f9G9X
function name:  (null)
number of ops:  17
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, <array>
   26     1        ASSIGN                                                   !1, <array>
   27     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'arraymergerecursivedistinct'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   28     9        INIT_FCALL                                               'print_r'
         10        INIT_FCALL                                               'array_replace_recursive'
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function arraymergerecursivedistinct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 30
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 27
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/f9G9X
function name:  arrayMergeRecursiveDistinct
number of ops:  33
compiled vars:  !0 = $first, !1 = $second, !2 = $value, !3 = $idx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2      > FE_RESET_R                                       $4      !1, ->30
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->30
          4    >   ASSIGN                                                   !3, ~5
    7     5        TYPE_CHECK                                   16          !3
          6      > JMPZ                                                     ~7, ->10
    8     7    >   ASSIGN_DIM                                               !0
          8        OP_DATA                                                  !2
          9      > JMP                                                      ->29
   10    10    >   ARRAY_KEY_EXISTS                                 ~9      !3, !0
         11        BOOL_NOT                                         ~10     ~9
         12      > JMPZ                                                     ~10, ->16
   11    13    >   ASSIGN_DIM                                               !0, !3
         14        OP_DATA                                                  !2
         15      > JMP                                                      ->29
   13    16    >   TYPE_CHECK                                  128          !2
         17      > JMPZ                                                     ~12, ->27
   14    18    >   INIT_FCALL_BY_NAME                                       'arrayMergeRecursiveDistinct'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $14     !0, !3
         21        SEND_FUNC_ARG                                            $14
         22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0  $15     
         24        ASSIGN_DIM                                               !0, !3
         25        OP_DATA                                                  $15
         26      > JMP                                                      ->29
   16    27    >   ASSIGN_DIM                                               !0, !3
         28        OP_DATA                                                  !2
    6    29    > > JMP                                                      ->3
         30    >   FE_FREE                                                  $4
   22    31      > RETURN                                                   !0
   23    32*     > RETURN                                                   null

End of function arraymergerecursivedistinct

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.15 ms | 1403 KiB | 18 Q