3v4l.org

run code in 300+ PHP versions simultaneously
<?php function translitUa($str) { $array = [ //'&'=>'ta', //'%'=>'', //'\''=>'', 'Зг'=>'Zgh', 'зг'=>'zgh', 'А'=>'A','а'=>'a', 'Б'=>'B','б'=>'b', 'В'=>'V','в'=>'v', 'Г'=>'H','г'=>'h', 'Ґ'=>'G','ґ'=>'g', 'Д'=>'D','д'=>'d', 'Е'=>'E','е'=>'e', 'Є'=>'Ye','є'=>'ie', 'Ж'=>'Zh','ж'=>'zh', 'З'=>'Z','з'=>'z', 'И'=>'Y','и'=>'y', 'І'=>'I','і'=>'i', 'Ї'=>'Yi','ї'=>'i', 'Й'=>'Y','й'=>'i', 'К'=>'K','к'=>'k', 'Л'=>'L','л'=>'l', 'М'=>'M','м'=>'m', 'Н'=>'N','н'=>'n', 'О'=>'O','о'=>'o', 'П'=>'P','п'=>'p', 'Р'=>'R','р'=>'r', 'С'=>'S','с'=>'s', 'Т'=>'T','т'=>'t', 'У'=>'U','у'=>'u', 'Ф'=>'F','ф'=>'f', 'Х'=>'Kh','х'=>'kh', 'Ц'=>'Ts','ц'=>'ts', 'Ч'=>'Ch','ч'=>'ch', 'Ш'=>'Sh','ш'=>'sh', 'Щ'=>'Shch','щ'=>'shch', 'Ь'=>'','ь'=>'', 'Ю'=>'Yu','ю'=>'iu', 'Я'=>'Ya','я'=>'ia' ]; return strtr($str,$array); } function wordcombos($words) { if ( count($words) <= 1 ) { $result = $words; } else { $result = array(); for ( $i = 0; $i < count($words); ++$i ) { $firstword = $words[$i]; $remainingwords = array(); for ( $j = 0; $j < count($words); ++$j ) { if ( $i <> $j ) $remainingwords[] = $words[$j]; } $combos = wordcombos($remainingwords); for ( $j = 0; $j < count($combos); ++$j ) { $result[] = $firstword . ' ' . $combos[$j]; } } } return $result; } function wordsArray($words, $data, $array = []) { if ($words === []) { return $array; } $word = array_shift($words); $subArray = wordsArray($words, $data, $array); if ($subArray === []) { $array[metaphone(translitUa($word))]['@data'] = $data; } else { $array[metaphone(translitUa($word))] = $subArray; } return $array; } $matches = [ 'розклад маршруток київ' => 'ось розклад маршруток київ', 'розклад автобусів київ' => 'ось розклад маршруток київ', 'розклад маршруток клавдієво' => 'ось розклад маршруток клавдієво', 'розклад автобусів клавдієво' => 'ось розклад маршруток клавдієво', 'розклад маршруток макарів' => 'ось розклад маршруток макарів', 'розклад автобусів макарів' => 'ось розклад маршруток макарів', 'розклад макарів' => 'ось розклад маршруток макарів', 'розклад електричок київ' => 'ось розклад електричок київ', 'розклад електричок' => 'ось розклад електричок київ', 'розклад електричок святошин' => 'ось розклад електричок київ', ]; function generateArray($matches) { $array = []; foreach ($matches as $keywords => $match) { $keywordsArray = explode(' ', $keywords); $combinations = wordcombos($keywordsArray); foreach ($combinations as $combination) { $words = explode(' ', $combination); $array = array_merge_recursive($array, wordsArray($words, $match)); } } return $array; } $array = generateArray($matches); function search($query, $array) { $query = str_replace([',', '.', ';', '-', '!', '?', "\r\n", "\n"], ' ', $query); $queryWords = explode(' ', $query); foreach ($queryWords as $word) { $wordMeta = metaphone(translitUa($word)); foreach ($array as $key => $value) { if (levenshtein($wordMeta, $key) < 2) { $array = $array[$key]; //var_dump($word . ' - ' . $wordMeta, $array); break; } } } if (isset($array['@data'])) { var_dump($array['@data']); } } search('У кого є розклад електричок на святошино?', $array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vgo4o
function name:  (null)
number of ops:  10
compiled vars:  !0 = $matches, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   ASSIGN                                                   !0, <array>
  115     1        INIT_FCALL                                               'generatearray'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
  140     5        INIT_FCALL                                               'search'
          6        SEND_VAL                                                 '%D0%A3+%D0%BA%D0%BE%D0%B3%D0%BE+%D1%94+%D1%80%D0%BE%D0%B7%D0%BA%D0%BB%D0%B0%D0%B4+%D0%B5%D0%BB%D0%B5%D0%BA%D1%82%D1%80%D0%B8%D1%87%D0%BE%D0%BA+%D0%BD%D0%B0+%D1%81%D0%B2%D1%8F%D1%82%D0%BE%D1%88%D0%B8%D0%BD%D0%BE%3F'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0          
          9      > RETURN                                                   1

Function translitua:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vgo4o
function name:  translitUa
number of ops:  8
compiled vars:  !0 = $str, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   46     2        INIT_FCALL                                               'strtr'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6      > RETURN                                                   $3
   47     7*     > RETURN                                                   null

End of function translitua

Function wordcombos:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 9
Branch analysis from position: 42
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 29
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 9
Branch analysis from position: 42
Branch analysis from position: 9
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 29
Branch analysis from position: 38
Branch analysis from position: 29
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 14
Branch analysis from position: 23
Branch analysis from position: 14
Branch analysis from position: 19
filename:       /in/Vgo4o
function name:  wordcombos
number of ops:  44
compiled vars:  !0 = $words, !1 = $result, !2 = $i, !3 = $firstword, !4 = $remainingwords, !5 = $j, !6 = $combos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   50     1        COUNT                                            ~7      !0
          2        IS_SMALLER_OR_EQUAL                                      ~7, 1
          3      > JMPZ                                                     ~8, ->6
   51     4    >   ASSIGN                                                   !1, !0
          5      > JMP                                                      ->42
   53     6    >   ASSIGN                                                   !1, <array>
   54     7        ASSIGN                                                   !2, 0
          8      > JMP                                                      ->39
   55     9    >   FETCH_DIM_R                                      ~12     !0, !2
         10        ASSIGN                                                   !3, ~12
   56    11        ASSIGN                                                   !4, <array>
   57    12        ASSIGN                                                   !5, 0
         13      > JMP                                                      ->20
   58    14    >   IS_NOT_EQUAL                                             !2, !5
         15      > JMPZ                                                     ~16, ->19
         16    >   FETCH_DIM_R                                      ~18     !0, !5
         17        ASSIGN_DIM                                               !4
         18        OP_DATA                                                  ~18
   57    19    >   PRE_INC                                                  !5
         20    >   COUNT                                            ~20     !0
         21        IS_SMALLER                                               !5, ~20
         22      > JMPNZ                                                    ~21, ->14
   60    23    >   INIT_FCALL_BY_NAME                                       'wordcombos'
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0  $22     
         26        ASSIGN                                                   !6, $22
   61    27        ASSIGN                                                   !5, 0
         28      > JMP                                                      ->35
   62    29    >   CONCAT                                           ~26     !3, '+'
         30        FETCH_DIM_R                                      ~27     !6, !5
         31        CONCAT                                           ~28     ~26, ~27
         32        ASSIGN_DIM                                               !1
         33        OP_DATA                                                  ~28
   61    34        PRE_INC                                                  !5
         35    >   COUNT                                            ~30     !6
         36        IS_SMALLER                                               !5, ~30
         37      > JMPNZ                                                    ~31, ->29
   54    38    >   PRE_INC                                                  !2
         39    >   COUNT                                            ~33     !0
         40        IS_SMALLER                                               !2, ~33
         41      > JMPNZ                                                    ~34, ->9
   66    42    > > RETURN                                                   !1
   67    43*     > RETURN                                                   null

End of function wordcombos

Function wordsarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vgo4o
function name:  wordsArray
number of ops:  38
compiled vars:  !0 = $words, !1 = $data, !2 = $array, !3 = $word, !4 = $subArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <array>
   70     3        IS_IDENTICAL                                             !0, <array>
          4      > JMPZ                                                     ~5, ->6
   71     5    > > RETURN                                                   !2
   73     6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !0
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !3, $6
   74    10        INIT_FCALL_BY_NAME                                       'wordsArray'
         11        SEND_VAR_EX                                              !0
         12        SEND_VAR_EX                                              !1
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $8      
         15        ASSIGN                                                   !4, $8
   75    16        IS_IDENTICAL                                             !4, <array>
         17      > JMPZ                                                     ~10, ->28
   76    18    >   INIT_FCALL                                               'metaphone'
         19        INIT_FCALL                                               'translitua'
         20        SEND_VAR                                                 !3
         21        DO_FCALL                                      0  $11     
         22        SEND_VAR                                                 $11
         23        DO_ICALL                                         $12     
         24        FETCH_DIM_W                                      $13     !2, $12
         25        ASSIGN_DIM                                               $13, '%40data'
         26        OP_DATA                                                  !1
         27      > JMP                                                      ->36
   78    28    >   INIT_FCALL                                               'metaphone'
         29        INIT_FCALL                                               'translitua'
         30        SEND_VAR                                                 !3
         31        DO_FCALL                                      0  $15     
         32        SEND_VAR                                                 $15
         33        DO_ICALL                                         $16     
         34        ASSIGN_DIM                                               !2, $16
         35        OP_DATA                                                  !4
   81    36    > > RETURN                                                   !2
   82    37*     > RETURN                                                   null

End of function wordsarray

Function generatearray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 33
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 33
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 31
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 31
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/Vgo4o
function name:  generateArray
number of ops:  36
compiled vars:  !0 = $matches, !1 = $array, !2 = $match, !3 = $keywords, !4 = $keywordsArray, !5 = $combinations, !6 = $combination, !7 = $words
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   98     0  E >   RECV                                             !0      
   99     1        ASSIGN                                                   !1, <array>
  101     2      > FE_RESET_R                                       $9      !0, ->33
          3    > > FE_FETCH_R                                       ~10     $9, !2, ->33
          4    >   ASSIGN                                                   !3, ~10
  102     5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '+'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $12     
          9        ASSIGN                                                   !4, $12
  103    10        INIT_FCALL                                               'wordcombos'
         11        SEND_VAR                                                 !4
         12        DO_FCALL                                      0  $14     
         13        ASSIGN                                                   !5, $14
  104    14      > FE_RESET_R                                       $16     !5, ->31
         15    > > FE_FETCH_R                                               $16, !6, ->31
  105    16    >   INIT_FCALL                                               'explode'
         17        SEND_VAL                                                 '+'
         18        SEND_VAR                                                 !6
         19        DO_ICALL                                         $17     
         20        ASSIGN                                                   !7, $17
  106    21        INIT_FCALL                                               'array_merge_recursive'
         22        SEND_VAR                                                 !1
         23        INIT_FCALL                                               'wordsarray'
         24        SEND_VAR                                                 !7
         25        SEND_VAR                                                 !2
         26        DO_FCALL                                      0  $19     
         27        SEND_VAR                                                 $19
         28        DO_ICALL                                         $20     
         29        ASSIGN                                                   !1, $20
  104    30      > JMP                                                      ->15
         31    >   FE_FREE                                                  $16
  101    32      > JMP                                                      ->3
         33    >   FE_FREE                                                  $9
  111    34      > RETURN                                                   !1
  113    35*     > RETURN                                                   null

End of function generatearray

Function search:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 37
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 37
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 35
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 35
Branch analysis from position: 35
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 44
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 37
filename:       /in/Vgo4o
function name:  search
number of ops:  45
compiled vars:  !0 = $query, !1 = $array, !2 = $queryWords, !3 = $word, !4 = $wordMeta, !5 = $value, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  118     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  119     2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 <array>
          4        SEND_VAL                                                 '+'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !0, $7
  120     8        INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '+'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !2, $9
  122    13      > FE_RESET_R                                       $11     !2, ->37
         14    > > FE_FETCH_R                                               $11, !3, ->37
  123    15    >   INIT_FCALL                                               'metaphone'
         16        INIT_FCALL                                               'translitua'
         17        SEND_VAR                                                 !3
         18        DO_FCALL                                      0  $12     
         19        SEND_VAR                                                 $12
         20        DO_ICALL                                         $13     
         21        ASSIGN                                                   !4, $13
  125    22      > FE_RESET_R                                       $15     !1, ->35
         23    > > FE_FETCH_R                                       ~16     $15, !5, ->35
         24    >   ASSIGN                                                   !6, ~16
  126    25        INIT_FCALL                                               'levenshtein'
         26        SEND_VAR                                                 !4
         27        SEND_VAR                                                 !6
         28        DO_ICALL                                         $18     
         29        IS_SMALLER                                               $18, 2
         30      > JMPZ                                                     ~19, ->34
  127    31    >   FETCH_DIM_R                                      ~20     !1, !6
         32        ASSIGN                                                   !1, ~20
  129    33      > JMP                                                      ->35
  125    34    > > JMP                                                      ->23
         35    >   FE_FREE                                                  $15
  122    36      > JMP                                                      ->14
         37    >   FE_FREE                                                  $11
  134    38        ISSET_ISEMPTY_DIM_OBJ                         0          !1, '%40data'
         39      > JMPZ                                                     ~22, ->44
  135    40    >   INIT_FCALL                                               'var_dump'
         41        FETCH_DIM_R                                      ~23     !1, '%40data'
         42        SEND_VAL                                                 ~23
         43        DO_ICALL                                                 
  138    44    > > RETURN                                                   null

End of function search

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.36 ms | 1418 KiB | 36 Q