3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_subtract(array $source, array $subtractor) { foreach ($subtractor as $subtractorItem) { $subtractorKey = array_search($subtractorItem, $source, true); if ($subtractorKey !== false) { unset($source[$subtractorKey]); } } return array_values($source); } var_dump(array_subtract([ 't', 'e', 's', 't' ], [ 't' ])); // [ 'e', 's', 't' ] var_dump(array_subtract([ 't', 'e', 's', 't' ], [ 't', 't' ])); // [ 'e', 's' ] var_dump(array_subtract([ 't', 'e', 's', 't' ], [ 't', 'e', 's', 't' ])); // [] var_dump(array_subtract([ 't', 'e', 's', 't' ], [ 'x' ])); // [ 't', 'e', 's', 't' ]
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/96frT
function name:  (null)
number of ops:  29
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'array_subtract'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   17     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'array_subtract'
          9        SEND_VAL                                                 <array>
         10        SEND_VAL                                                 <array>
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
   18    14        INIT_FCALL                                               'var_dump'
         15        INIT_FCALL                                               'array_subtract'
         16        SEND_VAL                                                 <array>
         17        SEND_VAL                                                 <array>
         18        DO_FCALL                                      0  $4      
         19        SEND_VAR                                                 $4
         20        DO_ICALL                                                 
   19    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'array_subtract'
         23        SEND_VAL                                                 <array>
         24        SEND_VAL                                                 <array>
         25        DO_FCALL                                      0  $6      
         26        SEND_VAR                                                 $6
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Function array_subtract:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/96frT
function name:  array_subtract
number of ops:  20
compiled vars:  !0 = $source, !1 = $subtractor, !2 = $subtractorItem, !3 = $subtractorKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2      > FE_RESET_R                                       $4      !1, ->14
          3    > > FE_FETCH_R                                               $4, !2, ->14
    6     4    >   INIT_FCALL                                               'array_search'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !3, $5
    8    10        TYPE_CHECK                                  1018          !3
         11      > JMPZ                                                     ~7, ->13
    9    12    >   UNSET_DIM                                                !0, !3
    5    13    > > JMP                                                      ->3
         14    >   FE_FREE                                                  $4
   13    15        INIT_FCALL                                               'array_values'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $8      
         18      > RETURN                                                   $8
   14    19*     > RETURN                                                   null

End of function array_subtract

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.98 ms | 1015 KiB | 20 Q