3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test1 = [ "blah1", "blah1", "blah2", "blah4", "blah5" ]; $test2 = [ "blah1", // under-represented "blah2", // equally found "blah3", // not found "blah4", // over-represented "blah4", // " ]; function removeBValuesFromA(array $a, array $b): array { foreach ($b as $bVal) { $k = array_search($bVal, $a); if ($k !== false) { unset($a[$k]); } } return array_values($a); } function bidirectionalDiff(array $a, array $b): array { foreach ($b as $bKey => $bVal) { $aKey = array_search($bVal, $a); if ($aKey !== false) { unset($a[$aKey], $b[$bKey]); } } return array_merge($a, $b); } function removeBValuesFromAViaCounts(array $a, array $b): array { $toRemove = array_count_values($b); $result = []; foreach (array_count_values($a) as $k => $count) { array_push( $result, ...array_fill( 0, max(0, $count - ($toRemove[$k] ?? 0)), $k ) ); } return $result; } function bidirectionalDiffViaCounts(array $a, array $b): array { $bCounts = array_count_values($b); $result = []; foreach (array_count_values($a) as $k => $count) { array_push( $result, ...array_fill( 0, abs($count - ($bCounts[$k] ?? 0)), $k ) ); unset($bCounts[$k]); } foreach ($bCounts as $k => $count) { array_push( $result, ...array_fill(0, $count, $k) ); } return $result; } var_export([ 'removeBValuesFromA' => removeBValuesFromA($test1, $test2), 'bidirectionalDiff' => bidirectionalDiff($test1, $test2), 'removeBValuesFromAViaCounts' => removeBValuesFromAViaCounts($test1, $test2), 'bidirectionalDiffViaCounts' => bidirectionalDiffViaCounts($test1, $test2), ]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GGG8t
function name:  (null)
number of ops:  26
compiled vars:  !0 = $test1, !1 = $test2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   84     2        INIT_FCALL                                               'var_export'
   85     3        INIT_FCALL                                               'removebvaluesfroma'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        INIT_ARRAY                                       ~5      $4, 'removeBValuesFromA'
   86     8        INIT_FCALL                                               'bidirectionaldiff'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $6      
         12        ADD_ARRAY_ELEMENT                                ~5      $6, 'bidirectionalDiff'
   87    13        INIT_FCALL                                               'removebvaluesfromaviacounts'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_FCALL                                      0  $7      
         17        ADD_ARRAY_ELEMENT                                ~5      $7, 'removeBValuesFromAViaCounts'
   88    18        INIT_FCALL                                               'bidirectionaldiffviacounts'
         19        SEND_VAR                                                 !0
         20        SEND_VAR                                                 !1
         21        DO_FCALL                                      0  $8      
         22        ADD_ARRAY_ELEMENT                                ~5      $8, 'bidirectionalDiffViaCounts'
         23        SEND_VAL                                                 ~5
   84    24        DO_ICALL                                                 
   89    25      > RETURN                                                   1

Function removebvaluesfroma:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/GGG8t
function name:  removeBValuesFromA
number of ops:  21
compiled vars:  !0 = $a, !1 = $b, !2 = $bVal, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2      > FE_RESET_R                                       $4      !1, ->13
          3    > > FE_FETCH_R                                               $4, !2, ->13
   22     4    >   INIT_FCALL                                               'array_search'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !3, $5
   23     9        TYPE_CHECK                                  1018          !3
         10      > JMPZ                                                     ~7, ->12
   24    11    >   UNSET_DIM                                                !0, !3
   21    12    > > JMP                                                      ->3
         13    >   FE_FREE                                                  $4
   27    14        INIT_FCALL                                               'array_values'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $8      
         17        VERIFY_RETURN_TYPE                                       $8
         18      > RETURN                                                   $8
   28    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function removebvaluesfroma

Function bidirectionaldiff:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/GGG8t
function name:  bidirectionalDiff
number of ops:  24
compiled vars:  !0 = $a, !1 = $b, !2 = $bVal, !3 = $bKey, !4 = $aKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     2      > FE_RESET_R                                       $5      !1, ->15
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->15
          4    >   ASSIGN                                                   !3, ~6
   33     5        INIT_FCALL                                               'array_search'
          6        SEND_VAR                                                 !2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !4, $8
   34    10        TYPE_CHECK                                  1018          !4
         11      > JMPZ                                                     ~10, ->14
   35    12    >   UNSET_DIM                                                !0, !4
         13        UNSET_DIM                                                !1, !3
   32    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $5
   38    16        INIT_FCALL                                               'array_merge'
         17        SEND_VAR                                                 !0
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $11     
         20        VERIFY_RETURN_TYPE                                       $11
         21      > RETURN                                                   $11
   39    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function bidirectionaldiff

Function removebvaluesfromaviacounts:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 32
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 32
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/GGG8t
function name:  removeBValuesFromAViaCounts
number of ops:  37
compiled vars:  !0 = $a, !1 = $b, !2 = $toRemove, !3 = $result, !4 = $count, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   43     2        INIT_FCALL                                               'array_count_values'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
   45     6        ASSIGN                                                   !3, <array>
   46     7        INIT_FCALL                                               'array_count_values'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $9      
         10      > FE_RESET_R                                       $10     $9, ->32
         11    > > FE_FETCH_R                                       ~11     $10, !4, ->32
         12    >   ASSIGN                                                   !5, ~11
   47    13        INIT_FCALL                                               'array_push'
   48    14        SEND_REF                                                 !3
   49    15        INIT_FCALL                                               'array_fill'
   50    16        SEND_VAL                                                 0
   51    17        INIT_FCALL                                               'max'
         18        SEND_VAL                                                 0
         19        FETCH_DIM_IS                                     ~13     !2, !5
         20        COALESCE                                         ~14     ~13
         21        QM_ASSIGN                                        ~14     0
         22        SUB                                              ~15     !4, ~14
         23        SEND_VAL                                                 ~15
         24        DO_ICALL                                         $16     
         25        SEND_VAR                                                 $16
   52    26        SEND_VAR                                                 !5
   49    27        DO_ICALL                                         $17     
   52    28        SEND_UNPACK                                              $17
         29        CHECK_UNDEF_ARGS                                         
   47    30        DO_ICALL                                                 
   46    31      > JMP                                                      ->11
         32    >   FE_FREE                                                  $10
   56    33        VERIFY_RETURN_TYPE                                       !3
         34      > RETURN                                                   !3
   57    35*       VERIFY_RETURN_TYPE                                       
         36*     > RETURN                                                   null

End of function removebvaluesfromaviacounts

Function bidirectionaldiffviacounts:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 32
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 32
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 34, Position 2 = 47
Branch analysis from position: 34
2 jumps found. (Code = 78) Position 1 = 35, Position 2 = 47
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 32
filename:       /in/GGG8t
function name:  bidirectionalDiffViaCounts
number of ops:  52
compiled vars:  !0 = $a, !1 = $b, !2 = $bCounts, !3 = $result, !4 = $count, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   61     2        INIT_FCALL                                               'array_count_values'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
   63     6        ASSIGN                                                   !3, <array>
   64     7        INIT_FCALL                                               'array_count_values'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $9      
         10      > FE_RESET_R                                       $10     $9, ->32
         11    > > FE_FETCH_R                                       ~11     $10, !4, ->32
         12    >   ASSIGN                                                   !5, ~11
   65    13        INIT_FCALL                                               'array_push'
   66    14        SEND_REF                                                 !3
   67    15        INIT_FCALL                                               'array_fill'
   68    16        SEND_VAL                                                 0
   69    17        INIT_FCALL                                               'abs'
         18        FETCH_DIM_IS                                     ~13     !2, !5
         19        COALESCE                                         ~14     ~13
         20        QM_ASSIGN                                        ~14     0
         21        SUB                                              ~15     !4, ~14
         22        SEND_VAL                                                 ~15
         23        DO_ICALL                                         $16     
         24        SEND_VAR                                                 $16
   70    25        SEND_VAR                                                 !5
   67    26        DO_ICALL                                         $17     
   70    27        SEND_UNPACK                                              $17
         28        CHECK_UNDEF_ARGS                                         
   65    29        DO_ICALL                                                 
   73    30        UNSET_DIM                                                !2, !5
   64    31      > JMP                                                      ->11
         32    >   FE_FREE                                                  $10
   75    33      > FE_RESET_R                                       $19     !2, ->47
         34    > > FE_FETCH_R                                       ~20     $19, !4, ->47
         35    >   ASSIGN                                                   !5, ~20
   76    36        INIT_FCALL                                               'array_push'
   77    37        SEND_REF                                                 !3
   78    38        INIT_FCALL                                               'array_fill'
         39        SEND_VAL                                                 0
         40        SEND_VAR                                                 !4
         41        SEND_VAR                                                 !5
         42        DO_ICALL                                         $22     
         43        SEND_UNPACK                                              $22
         44        CHECK_UNDEF_ARGS                                         
   76    45        DO_ICALL                                                 
   75    46      > JMP                                                      ->34
         47    >   FE_FREE                                                  $19
   81    48        VERIFY_RETURN_TYPE                                       !3
         49      > RETURN                                                   !3
   82    50*       VERIFY_RETURN_TYPE                                       
         51*     > RETURN                                                   null

End of function bidirectionaldiffviacounts

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.01 ms | 1030 KiB | 26 Q