3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Tools{ /** * Recursive version of array_diff_assoc * Returns everything from $a that is not in $b or the other arguments * * @param $a The array to compare from * @param $b An array to compare against * @param ... More arrays to compare against * * @return An array with everything from $a that not in $b or the others */ public static function array_diff_assoc_recursive($a, $b){ // Get all of the "compare against" arrays $b = array_slice(func_get_args(), 1); // Initial return value $ret = array(); // Loop over the "to" array and compare with the others foreach($a as $key=>$val){ // We should compare type first $aType = gettype($val); // If it's an array, we recurse, otherwise we just compare with "===" $args = $aType === 'array' ? array($val) : true; // Let's see what we have to compare to foreach($b as $x){ // If the key doesn't exist or the type is different, // then it's different, and our work here is done if(!array_key_exists($key, $x) || $aType !== gettype($x[$key])){ $ret[$key] = $val; continue 2; } // If we are working with arrays, then we recurse if($aType === 'array'){ $args[] = $x[$key]; } // Otherwise we just compare else{ $args = $args && $val === $x[$key]; } } // This is where we call ourselves with all of the arrays we got passed if($aType === 'array'){ $comp = call_user_func_array(array(get_called_class(), 'array_diff_assoc_recursive'), $args); // An empty array means we are equal :-) if(count($comp) > 0){ $ret[$key] = $comp; } } // If the values don't match, then we found a difference elseif(!$args){ $ret[$key] = $val; } } return $ret; } } $a = [[1, 2, 3], 4, [5, 6 ], 8, 10]; $b = [[ 2, 3], 4, [5, 6 ] ]; $c = [[1, 2 ], 4, [5, 6, 7] ]; $d = [[ 2 ], 4, [5, 6, 7], 8, 9 ]; var_export(Tools::array_diff_assoc_recursive($a, $b, $c, $d));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/E3Nol
function name:  (null)
number of ops:  14
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   ASSIGN                                                   !0, <array>
   63     1        ASSIGN                                                   !1, <array>
   64     2        ASSIGN                                                   !2, <array>
   65     3        ASSIGN                                                   !3, <array>
   67     4        INIT_FCALL                                               'var_export'
          5        INIT_STATIC_METHOD_CALL                                  'Tools', 'array_diff_assoc_recursive'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !2
          9        SEND_VAR                                                 !3
         10        DO_FCALL                                      0  $8      
         11        SEND_VAR                                                 $8
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Class Tools:
Function array_diff_assoc_recursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 65
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 65
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 43
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 43
Branch analysis from position: 19
2 jumps found. (Code = 47) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 37
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 41
Branch analysis from position: 26
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 60
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 59
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 64
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 64
Branch analysis from position: 43
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 43
Branch analysis from position: 18
Branch analysis from position: 43
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
filename:       /in/E3Nol
function name:  array_diff_assoc_recursive
number of ops:  68
compiled vars:  !0 = $a, !1 = $b, !2 = $ret, !3 = $val, !4 = $key, !5 = $aType, !6 = $args, !7 = $x, !8 = $comp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        FUNC_GET_ARGS                                    ~9      1
          3        ASSIGN                                                   !1, ~9
   17     4        ASSIGN                                                   !2, <array>
   20     5      > FE_RESET_R                                       $12     !0, ->65
          6    > > FE_FETCH_R                                       ~13     $12, !3, ->65
          7    >   ASSIGN                                                   !4, ~13
   22     8        GET_TYPE                                         ~15     !3
          9        ASSIGN                                                   !5, ~15
   24    10        IS_IDENTICAL                                             !5, 'array'
         11      > JMPZ                                                     ~17, ->15
         12    >   INIT_ARRAY                                       ~18     !3
         13        QM_ASSIGN                                        ~19     ~18
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~19     <true>
         16    >   ASSIGN                                                   !6, ~19
   27    17      > FE_RESET_R                                       $21     !1, ->43
         18    > > FE_FETCH_R                                               $21, !7, ->43
   30    19    >   ARRAY_KEY_EXISTS                                 ~22     !4, !7
         20        BOOL_NOT                                         ~23     ~22
         21      > JMPNZ_EX                                         ~23     ~23, ->26
         22    >   FETCH_DIM_R                                      ~24     !7, !4
         23        GET_TYPE                                         ~25     ~24
         24        IS_NOT_IDENTICAL                                 ~26     !5, ~25
         25        BOOL                                             ~23     ~26
         26    > > JMPZ                                                     ~23, ->31
   31    27    >   ASSIGN_DIM                                               !2, !4
         28        OP_DATA                                                  !3
   32    29        FE_FREE                                                  $21
         30      > JMP                                                      ->6
   36    31    >   IS_IDENTICAL                                             !5, 'array'
         32      > JMPZ                                                     ~28, ->37
   37    33    >   FETCH_DIM_R                                      ~30     !7, !4
         34        ASSIGN_DIM                                               !6
         35        OP_DATA                                                  ~30
   36    36      > JMP                                                      ->42
   41    37    > > JMPZ_EX                                          ~31     !6, ->41
         38    >   FETCH_DIM_R                                      ~32     !7, !4
         39        IS_IDENTICAL                                     ~33     !3, ~32
         40        BOOL                                             ~31     ~33
         41    >   ASSIGN                                                   !6, ~31
   27    42    > > JMP                                                      ->18
         43    >   FE_FREE                                                  $21
   46    44        IS_IDENTICAL                                             !5, 'array'
         45      > JMPZ                                                     ~35, ->60
   47    46    >   GET_CALLED_CLASS                                 ~36     
         47        INIT_ARRAY                                       ~37     ~36
         48        ADD_ARRAY_ELEMENT                                ~37     'array_diff_assoc_recursive'
         49        INIT_USER_CALL                                0          'call_user_func_array', ~37
         50        SEND_ARRAY                                               !6
         51        CHECK_UNDEF_ARGS                                         
         52        DO_FCALL                                      1  $38     
         53        ASSIGN                                                   !8, $38
   49    54        COUNT                                            ~40     !8
         55        IS_SMALLER                                               0, ~40
         56      > JMPZ                                                     ~41, ->59
   50    57    >   ASSIGN_DIM                                               !2, !4
         58        OP_DATA                                                  !8
   46    59    > > JMP                                                      ->64
   54    60    >   BOOL_NOT                                         ~43     !6
         61      > JMPZ                                                     ~43, ->64
   55    62    >   ASSIGN_DIM                                               !2, !4
         63        OP_DATA                                                  !3
   20    64    > > JMP                                                      ->6
         65    >   FE_FREE                                                  $12
   58    66      > RETURN                                                   !2
   59    67*     > RETURN                                                   null

End of function array_diff_assoc_recursive

End of class Tools.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
228.46 ms | 1009 KiB | 14 Q