3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** 初始化设置查询关键词和查询内容 **/ $names = array( '真三国无双', '无双剑姬', '虚无', '一时无两', '南无阿弥陀佛', '崖山之后无中国', ); $search = array("无","双"); /** 劈开字符串 **/ $res = array(); foreach($names as $name) { preg_match_all("/./u", $name, $match); $res[$name]['single'] = $match[0]; } print_r($res); /** 对字符串进行遍历,存储匹配到的位置,对没有匹配到所有的关键词的字符串剔除,匹配到所有的将位置相加,越小的排名越靠前 **/ foreach($res as $name => $v) { $pos = array(); foreach($v['single'] as $k => $s) { if(in_array($s, $search)) $pos[$s][] = $k; } if(count($pos) != count($search)) { unset($res[$name]); } else { $seq = 0; array_walk_recursive($pos, function($i) use(&$seq) { $seq += $i; }); $res[$name] = $seq; } } ksort($res); $res = array_keys($res); var_dump($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 53
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 53
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 36
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 36
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 35
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 36
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 15
filename:       /in/2WmVA
function name:  (null)
number of ops:  65
compiled vars:  !0 = $names, !1 = $search, !2 = $res, !3 = $name, !4 = $match, !5 = $v, !6 = $pos, !7 = $s, !8 = $k, !9 = $seq
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   14     2        ASSIGN                                                   !2, <array>
   15     3      > FE_RESET_R                                       $13     !0, ->15
          4    > > FE_FETCH_R                                               $13, !3, ->15
   16     5    >   INIT_FCALL                                               'preg_match_all'
          6        SEND_VAL                                                 '%2F.%2Fu'
          7        SEND_VAR                                                 !3
          8        SEND_REF                                                 !4
          9        DO_ICALL                                                 
   17    10        FETCH_DIM_R                                      ~17     !4, 0
         11        FETCH_DIM_W                                      $15     !2, !3
         12        ASSIGN_DIM                                               $15, 'single'
         13        OP_DATA                                                  ~17
   15    14      > JMP                                                      ->4
         15    >   FE_FREE                                                  $13
   19    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                                 
   22    19      > FE_RESET_R                                       $19     !2, ->53
         20    > > FE_FETCH_R                                       ~20     $19, !5, ->53
         21    >   ASSIGN                                                   !3, ~20
   23    22        ASSIGN                                                   !6, <array>
   24    23        FETCH_DIM_R                                      ~23     !5, 'single'
         24      > FE_RESET_R                                       $24     ~23, ->36
         25    > > FE_FETCH_R                                       ~25     $24, !7, ->36
         26    >   ASSIGN                                                   !8, ~25
   25    27        INIT_FCALL                                               'in_array'
         28        SEND_VAR                                                 !7
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $27     
         31      > JMPZ                                                     $27, ->35
         32    >   FETCH_DIM_W                                      $28     !6, !7
         33        ASSIGN_DIM                                               $28
         34        OP_DATA                                                  !8
   24    35    > > JMP                                                      ->25
         36    >   FE_FREE                                                  $24
   27    37        COUNT                                            ~30     !6
         38        COUNT                                            ~31     !1
         39        IS_NOT_EQUAL                                             ~30, ~31
         40      > JMPZ                                                     ~32, ->43
   28    41    >   UNSET_DIM                                                !2, !3
         42      > JMP                                                      ->52
   30    43    >   ASSIGN                                                   !9, 0
   31    44        INIT_FCALL                                               'array_walk_recursive'
         45        SEND_REF                                                 !6
         46        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F2WmVA%3A31%240'
         47        BIND_LEXICAL                                             ~34, !9
   33    48        SEND_VAL                                                 ~34
         49        DO_ICALL                                                 
   34    50        ASSIGN_DIM                                               !2, !3
         51        OP_DATA                                                  !9
   22    52    > > JMP                                                      ->20
         53    >   FE_FREE                                                  $19
   38    54        INIT_FCALL                                               'ksort'
         55        SEND_REF                                                 !2
         56        DO_ICALL                                                 
   39    57        INIT_FCALL                                               'array_keys'
         58        SEND_VAR                                                 !2
         59        DO_ICALL                                         $38     
         60        ASSIGN                                                   !2, $38
   41    61        INIT_FCALL                                               'var_dump'
         62        SEND_VAR                                                 !2
         63        DO_ICALL                                                 
         64      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F2WmVA%3A31%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2WmVA
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $i, !1 = $seq
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   32     2        ASSIGN_OP                                     1          !1, !0
   33     3      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F2WmVA%3A31%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.72 ms | 1400 KiB | 27 Q