3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_diff_assoc_recursive( ...$arrays ) { $i = \count( $arrays ); while ( --$i ) { $p = $i - 1; if ( \is_array( $arrays[ $i ] ) && \is_array( $arrays[ $p ] ) ) { foreach ( $arrays[ $i ] as $key => &$value ) { if ( ! \array_key_exists( $key, $arrays[ $p ] ) ) { // If the value doesn't exist in previous array, pass it along. $arrays[ $p ][ $key ] = $value; continue; } if ( $value === $arrays[ $p ][ $key ] || ( \is_array( $value ) && ! array_diff_assoc_recursive( ...array_column( $arrays, $key ) ) ) ) { // If there's no diff with the previous array or no diff can be found recursively, remove it from all the next arrays. foreach ( range( $p, $i ) as $_i ) if ( \is_array( $arrays[ $_i ] ) ) unset( $arrays[ $_i ][ $key ] ); continue; } } } } return $arrays[0]; } $array1 = array("a" => "green", "b" => "brown", "c" => "bluea" ); $array2 = array("a" => "green", "b" => "brown", "c" => "blue" ); var_dump( array_diff_assoc( $array1, $array2 ), array_diff_assoc_recursive( $array1, $array2 ), array_diff_assoc( $array1 ), array_diff_assoc_recursive( $array1 ), ); $a = [ 'one' => [ 1 => 'test', 2 => [ 'one', 'five', 'two', [ 'diff' => 'this', 'three' => 'four' ], ], ], 'two' => [ 1 => 'test2', 'two' => [ 'one', 'two', 'three' => 'four', 5, ], ], 'three', ]; $b = [ 'one' => [ 1 => 'test', 2 => [ 'one', 'five', 'two', [ 'three' => 'four', 'diff' => 'this' ], // 'one', 'two', [ 'diff' => 'this', 'three' => 'four' ], 'five', ], ], 'two' => [ 'two' => [ 'one', 'two', 5 => 4, 'three' => 'four', // 'one', 'two', 'three' => 'four', 5, ], 1 => 'test2', ], 'three', 'four', ]; var_dump( array_diff_assoc_recursive( $a, $b ), );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CuItX
function name:  (null)
number of ops:  32
compiled vars:  !0 = $array1, !1 = $array2, !2 = $a, !3 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, <array>
   37     1        ASSIGN                                                   !1, <array>
   39     2        INIT_FCALL                                               'var_dump'
   40     3        INIT_FCALL                                               'array_diff_assoc'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $6      
          7        SEND_VAR                                                 $6
   41     8        INIT_FCALL                                               'array_diff_assoc_recursive'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $7      
         12        SEND_VAR                                                 $7
   42    13        INIT_FCALL                                               'array_diff_assoc'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $8      
         16        SEND_VAR                                                 $8
   43    17        INIT_FCALL                                               'array_diff_assoc_recursive'
         18        SEND_VAR                                                 !0
         19        DO_FCALL                                      0  $9      
         20        SEND_VAR                                                 $9
   39    21        DO_ICALL                                                 
   46    22        ASSIGN                                                   !2, <array>
   61    23        ASSIGN                                                   !3, <array>
   80    24        INIT_FCALL                                               'var_dump'
   81    25        INIT_FCALL                                               'array_diff_assoc_recursive'
         26        SEND_VAR                                                 !2
         27        SEND_VAR                                                 !3
         28        DO_FCALL                                      0  $13     
         29        SEND_VAR                                                 $13
   80    30        DO_ICALL                                                 
   82    31      > RETURN                                                   1

Function array_diff_assoc_recursive:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 59
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 4
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 59
Branch analysis from position: 13
2 jumps found. (Code = 125) Position 1 = 15, Position 2 = 58
Branch analysis from position: 15
2 jumps found. (Code = 126) Position 1 = 16, Position 2 = 58
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 25
2 jumps found. (Code = 47) Position 1 = 29, Position 2 = 42
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 31, Position 2 = 41
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 57
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 55
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 55
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 54
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 55
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 41
Branch analysis from position: 42
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 4
Branch analysis from position: 61
Branch analysis from position: 4
Branch analysis from position: 58
Branch analysis from position: 59
Branch analysis from position: 12
filename:       /in/CuItX
function name:  array_diff_assoc_recursive
number of ops:  64
compiled vars:  !0 = $arrays, !1 = $i, !2 = $p, !3 = $value, !4 = $key, !5 = $_i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_VARIADIC                                    !0      
    5     1        COUNT                                            ~6      !0
          2        ASSIGN                                                   !1, ~6
    7     3      > JMP                                                      ->59
    8     4    >   SUB                                              ~8      !1, 1
          5        ASSIGN                                                   !2, ~8
   10     6        FETCH_DIM_R                                      ~10     !0, !1
          7        TYPE_CHECK                                  128  ~11     ~10
          8      > JMPZ_EX                                          ~11     ~11, ->12
          9    >   FETCH_DIM_R                                      ~12     !0, !2
         10        TYPE_CHECK                                  128  ~13     ~12
         11        BOOL                                             ~11     ~13
         12    > > JMPZ                                                     ~11, ->59
   11    13    >   FETCH_DIM_W                                      $14     !0, !1
         14      > FE_RESET_RW                                      $15     $14, ->58
         15    > > FE_FETCH_RW                                      ~16     $15, !3, ->58
         16    >   ASSIGN                                                   !4, ~16
   12    17        FETCH_DIM_R                                      ~18     !0, !2
         18        ARRAY_KEY_EXISTS                                 ~19     !4, ~18
         19        BOOL_NOT                                         ~20     ~19
         20      > JMPZ                                                     ~20, ->25
   14    21    >   FETCH_DIM_W                                      $21     !0, !2
         22        ASSIGN_DIM                                               $21, !4
         23        OP_DATA                                                  !3
   15    24      > JMP                                                      ->15
   19    25    >   FETCH_DIM_R                                      ~23     !0, !2
         26        FETCH_DIM_R                                      ~24     ~23, !4
         27        IS_IDENTICAL                                     ~25     !3, ~24
         28      > JMPNZ_EX                                         ~25     ~25, ->42
   20    29    >   TYPE_CHECK                                  128  ~26     !3
         30      > JMPZ_EX                                          ~26     ~26, ->41
         31    >   INIT_FCALL_BY_NAME                                       'array_diff_assoc_recursive'
         32        INIT_FCALL                                               'array_column'
         33        SEND_VAR                                                 !0
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                         $27     
         36        SEND_UNPACK                                              $27
         37        CHECK_UNDEF_ARGS                                         
         38        DO_FCALL                                      1  $28     
         39        BOOL_NOT                                         ~29     $28
         40        BOOL                                             ~26     ~29
         41    >   BOOL                                             ~25     ~26
         42    > > JMPZ                                                     ~25, ->57
   23    43    >   INIT_FCALL                                               'range'
         44        SEND_VAR                                                 !2
         45        SEND_VAR                                                 !1
         46        DO_ICALL                                         $30     
         47      > FE_RESET_R                                       $31     $30, ->55
         48    > > FE_FETCH_R                                               $31, !5, ->55
   24    49    >   FETCH_DIM_R                                      ~32     !0, !5
         50        TYPE_CHECK                                  128          ~32
         51      > JMPZ                                                     ~33, ->54
   25    52    >   FETCH_DIM_UNSET                                  $34     !0, !5
         53        UNSET_DIM                                                $34, !4
   23    54    > > JMP                                                      ->48
         55    >   FE_FREE                                                  $31
   27    56      > JMP                                                      ->15
   11    57    > > JMP                                                      ->15
         58    >   FE_FREE                                                  $15
    7    59    >   PRE_DEC                                          ~35     !1
         60      > JMPNZ                                                    ~35, ->4
   33    61    >   FETCH_DIM_R                                      ~36     !0, 0
         62      > RETURN                                                   ~36
   34    63*     > RETURN                                                   null

End of function array_diff_assoc_recursive

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.21 ms | 1025 KiB | 20 Q