3v4l.org

run code in 300+ PHP versions simultaneously
<?php $names = array( '真三国无双', '无双剑姬', '虚无', '一时无两', '南无阿弥陀佛', '崖山之后无中国', '折盒热熔压敏胶JH 1101' ); //拆分词语为单个字符 function split_name($name) { preg_match_all("/./u", $name, $arr); return $arr[0]; } //最长公共子序列 function LCS($str_1, $str_2) { $len_1 = strlen($str_1); $len_2 = strlen($str_2); $len = $len_1 > $len_2 ? $len_1 : $len_2; $dp = array(); for ($i = 0; $i <= $len; $i++) { $dp[$i] = array(); $dp[$i][0] = 0; $dp[0][$i] = 0; } for ($i = 1; $i <= $len_1; $i++) { for ($j = 1; $j <= $len_2; $j++) { if ($str_1[$i - 1] == $str_2[$j - 1]) { $dp[$i][$j] = $dp[$i - 1][$j - 1] + 1; } else { $dp[$i][$j] = $dp[$i - 1][$j] > $dp[$i][$j - 1] ? $dp[$i - 1][$j] : $dp[$i][$j - 1]; } } } return $dp[$len_1][$len_2]; } function search($name) { Global $names; $sort_list = array(); if (mb_strlen($name, 'utf-8') != strlen($name)) { // 是否全英文字符 $arr_1 = array_unique(split_name($name)); foreach ($names as $value) { $arr_2 = array_unique(split_name($value)); $similarity = count($arr_2) - count(array_diff($arr_2, $arr_1)); $sort_list[$value] = $similarity; } } else { foreach ($names as $value) { $similarity = LCS($name, $value); $sort_list[$value] = $similarity; } } arsort($sort_list); return $sort_list; } header('content-type:text/html;charset=utf-8'); print_r(search('中国'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sqZX9
function name:  (null)
number of ops:  11
compiled vars:  !0 = $names
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   66     1        INIT_FCALL                                               'header'
          2        SEND_VAL                                                 'content-type%3Atext%2Fhtml%3Bcharset%3Dutf-8'
          3        DO_ICALL                                                 
   67     4        INIT_FCALL                                               'print_r'
          5        INIT_FCALL                                               'search'
          6        SEND_VAL                                                 '%E4%B8%AD%E5%9B%BD'
          7        DO_FCALL                                      0  $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function split_name:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sqZX9
function name:  split_name
number of ops:  9
compiled vars:  !0 = $name, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F.%2Fu'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   15     6        FETCH_DIM_R                                      ~3      !1, 0
          7      > RETURN                                                   ~3
   16     8*     > RETURN                                                   null

End of function split_name

Function lcs:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 15
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 28
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 30
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 28
Branch analysis from position: 71
Branch analysis from position: 28
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 45
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 30
Branch analysis from position: 68
Branch analysis from position: 30
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 58
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 30
Branch analysis from position: 68
Branch analysis from position: 30
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 30
Branch analysis from position: 68
Branch analysis from position: 30
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 15
Branch analysis from position: 26
Branch analysis from position: 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
filename:       /in/sqZX9
function name:  LCS
number of ops:  75
compiled vars:  !0 = $str_1, !1 = $str_2, !2 = $len_1, !3 = $len_2, !4 = $len, !5 = $dp, !6 = $i, !7 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        STRLEN                                           ~8      !0
          3        ASSIGN                                                   !2, ~8
   21     4        STRLEN                                           ~10     !1
          5        ASSIGN                                                   !3, ~10
   22     6        IS_SMALLER                                               !3, !2
          7      > JMPZ                                                     ~12, ->10
          8    >   QM_ASSIGN                                        ~13     !2
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~13     !3
         11    >   ASSIGN                                                   !4, ~13
   24    12        ASSIGN                                                   !5, <array>
   25    13        ASSIGN                                                   !6, 0
         14      > JMP                                                      ->24
   26    15    >   ASSIGN_DIM                                               !5, !6
         16        OP_DATA                                                  <array>
   27    17        FETCH_DIM_W                                      $18     !5, !6
         18        ASSIGN_DIM                                               $18, 0
         19        OP_DATA                                                  0
   28    20        FETCH_DIM_W                                      $20     !5, 0
         21        ASSIGN_DIM                                               $20, !6
         22        OP_DATA                                                  0
   25    23        PRE_INC                                                  !6
         24    >   IS_SMALLER_OR_EQUAL                                      !6, !4
         25      > JMPNZ                                                    ~23, ->15
   31    26    >   ASSIGN                                                   !6, 1
         27      > JMP                                                      ->69
   32    28    >   ASSIGN                                                   !7, 1
         29      > JMP                                                      ->66
   33    30    >   SUB                                              ~26     !6, 1
         31        FETCH_DIM_R                                      ~27     !0, ~26
         32        SUB                                              ~28     !7, 1
         33        FETCH_DIM_R                                      ~29     !1, ~28
         34        IS_EQUAL                                                 ~27, ~29
         35      > JMPZ                                                     ~30, ->45
   34    36    >   SUB                                              ~33     !6, 1
         37        SUB                                              ~35     !7, 1
         38        FETCH_DIM_R                                      ~34     !5, ~33
         39        FETCH_DIM_R                                      ~36     ~34, ~35
         40        ADD                                              ~37     ~36, 1
         41        FETCH_DIM_W                                      $31     !5, !6
         42        ASSIGN_DIM                                               $31, !7
         43        OP_DATA                                                  ~37
         44      > JMP                                                      ->65
   36    45    >   SUB                                              ~40     !6, 1
         46        FETCH_DIM_R                                      ~41     !5, ~40
         47        FETCH_DIM_R                                      ~42     ~41, !7
         48        SUB                                              ~44     !7, 1
         49        FETCH_DIM_R                                      ~43     !5, !6
         50        FETCH_DIM_R                                      ~45     ~43, ~44
         51        IS_SMALLER                                               ~45, ~42
         52      > JMPZ                                                     ~46, ->58
         53    >   SUB                                              ~47     !6, 1
         54        FETCH_DIM_R                                      ~48     !5, ~47
         55        FETCH_DIM_R                                      ~49     ~48, !7
         56        QM_ASSIGN                                        ~50     ~49
         57      > JMP                                                      ->62
         58    >   SUB                                              ~52     !7, 1
         59        FETCH_DIM_R                                      ~51     !5, !6
         60        FETCH_DIM_R                                      ~53     ~51, ~52
         61        QM_ASSIGN                                        ~50     ~53
         62    >   FETCH_DIM_W                                      $38     !5, !6
         63        ASSIGN_DIM                                               $38, !7
         64        OP_DATA                                                  ~50
   32    65    >   PRE_INC                                                  !7
         66    >   IS_SMALLER_OR_EQUAL                                      !7, !3
         67      > JMPNZ                                                    ~55, ->30
   31    68    >   PRE_INC                                                  !6
         69    >   IS_SMALLER_OR_EQUAL                                      !6, !2
         70      > JMPNZ                                                    ~57, ->28
   41    71    >   FETCH_DIM_R                                      ~58     !5, !2
         72        FETCH_DIM_R                                      ~59     ~58, !3
         73      > RETURN                                                   ~59
   42    74*     > RETURN                                                   null

End of function lcs

Function search:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 39
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 37
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 37
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 49
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 49
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
filename:       /in/sqZX9
function name:  search
number of ops:  55
compiled vars:  !0 = $name, !1 = $names, !2 = $sort_list, !3 = $arr_1, !4 = $value, !5 = $arr_2, !6 = $similarity
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        BIND_GLOBAL                                              !1, 'names'
   47     2        ASSIGN                                                   !2, <array>
   48     3        INIT_FCALL                                               'mb_strlen'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'utf-8'
          6        DO_ICALL                                         $8      
          7        STRLEN                                           ~9      !0
          8        IS_NOT_EQUAL                                             $8, ~9
          9      > JMPZ                                                     ~10, ->39
   49    10    >   INIT_FCALL                                               'array_unique'
         11        INIT_FCALL                                               'split_name'
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0  $11     
         14        SEND_VAR                                                 $11
         15        DO_ICALL                                         $12     
         16        ASSIGN                                                   !3, $12
   50    17      > FE_RESET_R                                       $14     !1, ->37
         18    > > FE_FETCH_R                                               $14, !4, ->37
   51    19    >   INIT_FCALL                                               'array_unique'
         20        INIT_FCALL                                               'split_name'
         21        SEND_VAR                                                 !4
         22        DO_FCALL                                      0  $15     
         23        SEND_VAR                                                 $15
         24        DO_ICALL                                         $16     
         25        ASSIGN                                                   !5, $16
   52    26        COUNT                                            ~18     !5
         27        INIT_FCALL                                               'array_diff'
         28        SEND_VAR                                                 !5
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $19     
         31        COUNT                                            ~20     $19
         32        SUB                                              ~21     ~18, ~20
         33        ASSIGN                                                   !6, ~21
   53    34        ASSIGN_DIM                                               !2, !4
         35        OP_DATA                                                  !6
   50    36      > JMP                                                      ->18
         37    >   FE_FREE                                                  $14
         38      > JMP                                                      ->50
   56    39    > > FE_RESET_R                                       $24     !1, ->49
         40    > > FE_FETCH_R                                               $24, !4, ->49
   57    41    >   INIT_FCALL                                               'lcs'
         42        SEND_VAR                                                 !0
         43        SEND_VAR                                                 !4
         44        DO_FCALL                                      0  $25     
         45        ASSIGN                                                   !6, $25
   58    46        ASSIGN_DIM                                               !2, !4
         47        OP_DATA                                                  !6
   56    48      > JMP                                                      ->40
         49    >   FE_FREE                                                  $24
   61    50    >   INIT_FCALL                                               'arsort'
         51        SEND_REF                                                 !2
         52        DO_ICALL                                                 
   63    53      > RETURN                                                   !2
   64    54*     > RETURN                                                   null

End of function search

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.87 ms | 1414 KiB | 31 Q