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]; } /** 对字符串进行遍历,存储匹配到的位置,对没有匹配到所有的关键词的字符串剔除,匹配到所有的将位置相加,越小的排名越靠前 **/ 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 = 17, Position 2 = 50
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 50
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 32
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 33
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
Branch analysis from position: 15
filename:       /in/K0X7m
function name:  (null)
number of ops:  62
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
   21    16      > FE_RESET_R                                       $18     !2, ->50
         17    > > FE_FETCH_R                                       ~19     $18, !5, ->50
         18    >   ASSIGN                                                   !3, ~19
   22    19        ASSIGN                                                   !6, <array>
   23    20        FETCH_DIM_R                                      ~22     !5, 'single'
         21      > FE_RESET_R                                       $23     ~22, ->33
         22    > > FE_FETCH_R                                       ~24     $23, !7, ->33
         23    >   ASSIGN                                                   !8, ~24
   24    24        INIT_FCALL                                               'in_array'
         25        SEND_VAR                                                 !7
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                         $26     
         28      > JMPZ                                                     $26, ->32
         29    >   FETCH_DIM_W                                      $27     !6, !7
         30        ASSIGN_DIM                                               $27
         31        OP_DATA                                                  !8
   23    32    > > JMP                                                      ->22
         33    >   FE_FREE                                                  $23
   26    34        COUNT                                            ~29     !6
         35        COUNT                                            ~30     !1
         36        IS_NOT_EQUAL                                             ~29, ~30
         37      > JMPZ                                                     ~31, ->40
   27    38    >   UNSET_DIM                                                !2, !3
         39      > JMP                                                      ->49
   29    40    >   ASSIGN                                                   !9, 0
   30    41        INIT_FCALL                                               'array_walk_recursive'
         42        SEND_REF                                                 !6
         43        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FK0X7m%3A30%240'
         44        BIND_LEXICAL                                             ~33, !9
   32    45        SEND_VAL                                                 ~33
         46        DO_ICALL                                                 
   33    47        ASSIGN_DIM                                               !2, !3
         48        OP_DATA                                                  !9
   21    49    > > JMP                                                      ->17
         50    >   FE_FREE                                                  $18
   37    51        INIT_FCALL                                               'ksort'
         52        SEND_REF                                                 !2
         53        DO_ICALL                                                 
   38    54        INIT_FCALL                                               'array_keys'
         55        SEND_VAR                                                 !2
         56        DO_ICALL                                         $37     
         57        ASSIGN                                                   !2, $37
   40    58        INIT_FCALL                                               'var_dump'
         59        SEND_VAR                                                 !2
         60        DO_ICALL                                                 
         61      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2FK0X7m%3A30%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.83 ms | 1400 KiB | 25 Q