3v4l.org

run code in 500+ PHP versions simultaneously
<?php $a = [ [ 'id' => 20, 'created_at' => '2020-11-22', 'updated_at' => '2020-11-22 11:16:22', 'name' => 'AA', ], [ 'id' => 19, 'created_at' => '2020-11-27 11:16:22', 'updated_at' => null, 'name' => 'BB', ] ]; $b = [ [ 'id' => 20, 'created_at' => '2020-11-22 11:16:11', 'updated_at' => '2020-11-22 11:16:22', 'name' => 'AA', ], [ 'id' => 19, 'created_at' => '2020-11-27 11:16:22', 'updated_at' => null, 'name' => 'BB', ] ]; function array_diff_by_keys(array $a, array $b, array $keys = null) { if (empty($keys)) $keys = array_keys(reset($a)); $compare = function ($x, $y) use ($keys) { foreach ($keys as $key) { $diff = $x[$key] <=> $y[$key]; if ($diff) return $diff; } return $diff; }; return array_udiff($a, $b, $compare); } print_r(array_diff_by_keys($a, $b)); print_r(array_diff_by_keys($a, $b, ['id', 'created_at', 'updated_at']));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1dPON
function name:  (null)
number of ops:  18
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   18     1        ASSIGN                                                       !1, <array>
   49     2        INIT_FCALL                                                   'print_r'
          3        INIT_FCALL                                                   'array_diff_by_keys'
          4        SEND_VAR                                                     !0
          5        SEND_VAR                                                     !1
          6        DO_FCALL                                          0  $4      
          7        SEND_VAR                                                     $4
          8        DO_ICALL                                                     
   50     9        INIT_FCALL                                                   'print_r'
         10        INIT_FCALL                                                   'array_diff_by_keys'
         11        SEND_VAR                                                     !0
         12        SEND_VAR                                                     !1
         13        SEND_VAL                                                     <array>
         14        DO_FCALL                                          0  $6      
         15        SEND_VAR                                                     $6
         16        DO_ICALL                                                     
         17      > RETURN                                                       1

Function array_diff_by_keys:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/1dPON
function name:  array_diff_by_keys
number of ops:  22
compiled vars:  !0 = $a, !1 = $b, !2 = $keys, !3 = $compare
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      null
   36     3        ISSET_ISEMPTY_CV                                             !2
          4      > JMPZ                                                         ~4, ->12
          5    >   INIT_FCALL                                                   'array_keys'
          6        INIT_FCALL                                                   'reset'
          7        SEND_REF                                                     !0
          8        DO_ICALL                                             $5      
          9        SEND_VAR                                                     $5
         10        DO_ICALL                                             $6      
         11        ASSIGN                                                       !2, $6
   38    12    >   DECLARE_LAMBDA_FUNCTION                              ~8      [0]
         13        BIND_LEXICAL                                                 ~8, !2
         14        ASSIGN                                                       !3, ~8
   46    15        INIT_FCALL                                                   'array_udiff'
         16        SEND_VAR                                                     !0
         17        SEND_VAR                                                     !1
         18        SEND_VAR                                                     !3
         19        DO_ICALL                                             $10     
         20      > RETURN                                                       $10
   47    21*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/1dPON
function name:  {closure:array_diff_by_keys():38}
number of ops:  16
compiled vars:  !0 = $x, !1 = $y, !2 = $keys, !3 = $key, !4 = $diff
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   39     3      > FE_RESET_R                                           $5      !2, ->13
          4    > > FE_FETCH_R                                                   $5, !3, ->13
   40     5    >   FETCH_DIM_R                                          ~6      !0, !3
          6        FETCH_DIM_R                                          ~7      !1, !3
          7        SPACESHIP                                            ~8      ~6, ~7
          8        ASSIGN                                                       !4, ~8
   41     9      > JMPZ                                                         !4, ->12
         10    >   FE_FREE                                                      $5
         11      > RETURN                                                       !4
   39    12    > > JMP                                                          ->4
         13    >   FE_FREE                                                      $5
   43    14      > RETURN                                                       !4
   44    15*     > RETURN                                                       null

End of Dynamic Function 0

End of function array_diff_by_keys

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
235.62 ms | 2136 KiB | 19 Q