3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str1 = "Samsung Television 21 Inches LED BH005DE"; $str2 = "Samsung 21 Inch LED TV"; //synonyms: $syns = [ 'TV' => ['TV', 'Television'], 'Inch' => ['Inch', 'Inches'] ]; //replace: $str1 = array_reduce(array_keys($syns), function($c, $x) use ($syns) { return $c = preg_replace('/\b'.join('\b|\b', $syns[$x]).'\b/', $x, $c); }, $str1); //now, str1 looks like "Samsung TV 21 Inch LED BH005DE" $str2 = array_reduce(array_keys($syns), function($c, $x) use ($syns) { return $c = preg_replace('/\b'.join('\b|\b', $syns[$x]).'\b/', $x, $c); }, $str2); //now, str2 looks like "Samsung 21 Inch LED TV" $arr1 = explode(' ', $str1); $arr2 = explode(' ', $str2); var_dump(array_diff($arr1, $arr2));//['BH005DE']
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d7csn
function name:  (null)
number of ops:  43
compiled vars:  !0 = $str1, !1 = $str2, !2 = $syns, !3 = $arr1, !4 = $arr2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'Samsung+Television+21+Inches+LED+BH005DE'
    3     1        ASSIGN                                                   !1, 'Samsung+21+Inch+LED+TV'
    6     2        ASSIGN                                                   !2, <array>
   12     3        INIT_FCALL                                               'array_reduce'
          4        INIT_FCALL                                               'array_keys'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $8      
          7        SEND_VAR                                                 $8
          8        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fd7csn%3A12%240'
          9        BIND_LEXICAL                                             ~9, !2
   15    10        SEND_VAL                                                 ~9
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $10     
   12    13        ASSIGN                                                   !0, $10
   18    14        INIT_FCALL                                               'array_reduce'
         15        INIT_FCALL                                               'array_keys'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $12     
         18        SEND_VAR                                                 $12
         19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fd7csn%3A18%241'
         20        BIND_LEXICAL                                             ~13, !2
   21    21        SEND_VAL                                                 ~13
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $14     
   18    24        ASSIGN                                                   !1, $14
   24    25        INIT_FCALL                                               'explode'
         26        SEND_VAL                                                 '+'
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $16     
         29        ASSIGN                                                   !3, $16
   25    30        INIT_FCALL                                               'explode'
         31        SEND_VAL                                                 '+'
         32        SEND_VAR                                                 !1
         33        DO_ICALL                                         $18     
         34        ASSIGN                                                   !4, $18
   28    35        INIT_FCALL                                               'var_dump'
         36        INIT_FCALL                                               'array_diff'
         37        SEND_VAR                                                 !3
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                         $20     
         40        SEND_VAR                                                 $20
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fd7csn%3A12%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d7csn
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $c, !1 = $x, !2 = $syns
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   14     3        INIT_FCALL                                               'preg_replace'
          4        INIT_FCALL                                               'join'
          5        SEND_VAL                                                 '%5Cb%7C%5Cb'
          6        FETCH_DIM_R                                      ~3      !2, !1
          7        SEND_VAL                                                 ~3
          8        DO_ICALL                                         $4      
          9        CONCAT                                           ~5      '%2F%5Cb', $4
         10        CONCAT                                           ~6      ~5, '%5Cb%2F'
         11        SEND_VAL                                                 ~6
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $7      
         15        ASSIGN                                           ~8      !0, $7
         16      > RETURN                                                   ~8
   15    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fd7csn%3A12%240

Function %00%7Bclosure%7D%2Fin%2Fd7csn%3A18%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d7csn
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $c, !1 = $x, !2 = $syns
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   20     3        INIT_FCALL                                               'preg_replace'
          4        INIT_FCALL                                               'join'
          5        SEND_VAL                                                 '%5Cb%7C%5Cb'
          6        FETCH_DIM_R                                      ~3      !2, !1
          7        SEND_VAL                                                 ~3
          8        DO_ICALL                                         $4      
          9        CONCAT                                           ~5      '%2F%5Cb', $4
         10        CONCAT                                           ~6      ~5, '%5Cb%2F'
         11        SEND_VAL                                                 ~6
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $7      
         15        ASSIGN                                           ~8      !0, $7
         16      > RETURN                                                   ~8
   21    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fd7csn%3A18%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.24 ms | 1400 KiB | 27 Q