3v4l.org

run code in 300+ PHP versions simultaneously
<?php $user_string = "hallo worl, I wnt to ind a resturan in manhatn"; $subj = explode(" ", $user_string); $str = ["hello", "world", "I", "want", "to", "a", "in" , "find", "eat", "restaurant", "pizza", "Manhattan"]; $minStr = ""; $minDis = PHP_INT_MAX; foreach ($str as $curStr) { Foreach($subj as $word){ $dis = levenshtein($word, $curStr); $dist[$word][$dis][] = $curStr; } } foreach($dist as $key => $word){ echo "the closest word to " . $key . " is " . implode(" and ", $word[min(array_keys($word))]) . "\n"; $sentence[] = implode(" and ", $word[min(array_keys($word))]); } Echo "\n\nUser probably meant: '" .implode(" ", $sentence) . "'";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 25
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 23
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 59
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 59
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
Branch analysis from position: 25
filename:       /in/hB7Ge
function name:  (null)
number of ops:  68
compiled vars:  !0 = $user_string, !1 = $subj, !2 = $str, !3 = $minStr, !4 = $minDis, !5 = $curStr, !6 = $word, !7 = $dis, !8 = $dist, !9 = $key, !10 = $sentence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'hallo+worl%2C+I+wnt+to+ind+a+resturan+in+manhatn'
    4     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $12     
          5        ASSIGN                                                   !1, $12
    6     6        ASSIGN                                                   !2, <array>
    8     7        ASSIGN                                                   !3, ''
    9     8        ASSIGN                                                   !4, 9223372036854775807
   10     9      > FE_RESET_R                                       $17     !2, ->25
         10    > > FE_FETCH_R                                               $17, !5, ->25
   11    11    > > FE_RESET_R                                       $18     !1, ->23
         12    > > FE_FETCH_R                                               $18, !6, ->23
   12    13    >   INIT_FCALL                                               'levenshtein'
         14        SEND_VAR                                                 !6
         15        SEND_VAR                                                 !5
         16        DO_ICALL                                         $19     
         17        ASSIGN                                                   !7, $19
   13    18        FETCH_DIM_W                                      $21     !8, !6
         19        FETCH_DIM_W                                      $22     $21, !7
         20        ASSIGN_DIM                                               $22
         21        OP_DATA                                                  !5
   11    22      > JMP                                                      ->12
         23    >   FE_FREE                                                  $18
   10    24      > JMP                                                      ->10
         25    >   FE_FREE                                                  $17
   18    26      > FE_RESET_R                                       $24     !8, ->59
         27    > > FE_FETCH_R                                       ~25     $24, !6, ->59
         28    >   ASSIGN                                                   !9, ~25
   19    29        CONCAT                                           ~27     'the+closest+word+to+', !9
         30        CONCAT                                           ~28     ~27, '+is+'
         31        INIT_FCALL                                               'implode'
         32        SEND_VAL                                                 '+and+'
         33        INIT_FCALL                                               'min'
         34        INIT_FCALL                                               'array_keys'
         35        SEND_VAR                                                 !6
         36        DO_ICALL                                         $29     
         37        SEND_VAR                                                 $29
         38        DO_ICALL                                         $30     
         39        FETCH_DIM_R                                      ~31     !6, $30
         40        SEND_VAL                                                 ~31
         41        DO_ICALL                                         $32     
         42        CONCAT                                           ~33     ~28, $32
         43        CONCAT                                           ~34     ~33, '%0A'
         44        ECHO                                                     ~34
   20    45        INIT_FCALL                                               'implode'
         46        SEND_VAL                                                 '+and+'
         47        INIT_FCALL                                               'min'
         48        INIT_FCALL                                               'array_keys'
         49        SEND_VAR                                                 !6
         50        DO_ICALL                                         $36     
         51        SEND_VAR                                                 $36
         52        DO_ICALL                                         $37     
         53        FETCH_DIM_R                                      ~38     !6, $37
         54        SEND_VAL                                                 ~38
         55        DO_ICALL                                         $39     
         56        ASSIGN_DIM                                               !10
         57        OP_DATA                                                  $39
   18    58      > JMP                                                      ->27
         59    >   FE_FREE                                                  $24
   23    60        INIT_FCALL                                               'implode'
         61        SEND_VAL                                                 '+'
         62        SEND_VAR                                                 !10
         63        DO_ICALL                                         $40     
         64        CONCAT                                           ~41     '%0A%0AUser+probably+meant%3A+%27', $40
         65        CONCAT                                           ~42     ~41, '%27'
         66        ECHO                                                     ~42
         67      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.02 ms | 1020 KiB | 18 Q