3v4l.org

run code in 300+ PHP versions simultaneously
<?php function checkCase($string) { // --- 列出标点的转换规则 $symMap = [ "." => ">", "," => "<" ]; foreach($symMap as $k => $v) $symMap[$v] = $k; // 列出标点的转换规则 --- // --- 列出各种可能情况 // $element = [["a", "A"], [".", ">"], ["b", "B"]] $element = str_split($string); foreach($element as &$item) { if(in_array($item, $symMap)) $item = [$item, $symMap[$item]]; else $item = [strtolower($item), strtoupper($item)]; } // 列出各种可能情况 --- // 记录当前的组合状态,每一项对应 $element 中的每一项 $flags = array_fill(0, count($element), 0); // 记录结果 $result = []; while(true) { $solution = ""; // 组合当前一条结果 foreach(range(0, count($element) - 1) as $i) $solution .= $element[$i][$flags[$i]]; // 改变当前状态,同时返回是否已经到达了末尾 $isEnding = function() use(&$flags, $element) { foreach(range(0, count($flags) - 1) as $i) { if($flags[$i] < count($element[$i]) - 1) { $flags[$i]++; if($i > 0) foreach(range(0, $i - 1) as $j) $flags[$j] = 0; return false; } } return true; }; if(!$isEnding()) $result[] = $solution; else break; } return $result; } var_dump(checkCase("A.B")); var_dump(checkCase("ABCD"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VOtvl
function name:  (null)
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'checkcase'
          2        SEND_VAL                                                 'A.B'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   69     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'checkcase'
          8        SEND_VAL                                                 'ABCD'
          9        DO_FCALL                                      0  $2      
         10        SEND_VAR                                                 $2
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function checkcase:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
2 jumps found. (Code = 125) Position 1 = 14, Position 2 = 35
Branch analysis from position: 14
2 jumps found. (Code = 126) Position 1 = 15, Position 2 = 35
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 73, Position 2 = 45
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 77) Position 1 = 53, Position 2 = 59
Branch analysis from position: 53
2 jumps found. (Code = 78) Position 1 = 54, Position 2 = 59
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 71
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 59
Branch analysis from position: 35
Branch analysis from position: 8
filename:       /in/VOtvl
function name:  checkCase
number of ops:  75
compiled vars:  !0 = $string, !1 = $symMap, !2 = $v, !3 = $k, !4 = $element, !5 = $item, !6 = $flags, !7 = $result, !8 = $solution, !9 = $i, !10 = $isEnding
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    6     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $12     !1, ->8
          3    > > FE_FETCH_R                                       ~13     $12, !2, ->8
          4    >   ASSIGN                                                   !3, ~13
   12     5        ASSIGN_DIM                                               !1, !2
          6        OP_DATA                                                  !3
   11     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $12
   17     9        INIT_FCALL                                               'str_split'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $16     
         12        ASSIGN                                                   !4, $16
   19    13      > FE_RESET_RW                                      $18     !4, ->35
         14    > > FE_FETCH_RW                                              $18, !5, ->35
   21    15    >   INIT_FCALL                                               'in_array'
         16        SEND_VAR                                                 !5
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $19     
         19      > JMPZ                                                     $19, ->25
   22    20    >   INIT_ARRAY                                       ~20     !5
         21        FETCH_DIM_R                                      ~21     !1, !5
         22        ADD_ARRAY_ELEMENT                                ~20     ~21
         23        ASSIGN                                                   !5, ~20
         24      > JMP                                                      ->34
   24    25    >   INIT_FCALL                                               'strtolower'
         26        SEND_VAR                                                 !5
         27        DO_ICALL                                         $23     
         28        INIT_ARRAY                                       ~24     $23
         29        INIT_FCALL                                               'strtoupper'
         30        SEND_VAR                                                 !5
         31        DO_ICALL                                         $25     
         32        ADD_ARRAY_ELEMENT                                ~24     $25
         33        ASSIGN                                                   !5, ~24
   19    34    > > JMP                                                      ->14
         35    >   FE_FREE                                                  $18
   29    36        INIT_FCALL                                               'array_fill'
         37        SEND_VAL                                                 0
         38        COUNT                                            ~27     !4
         39        SEND_VAL                                                 ~27
         40        SEND_VAL                                                 0
         41        DO_ICALL                                         $28     
         42        ASSIGN                                                   !6, $28
   31    43        ASSIGN                                                   !7, <array>
   33    44      > JMP                                                      ->72
   35    45    >   ASSIGN                                                   !8, ''
   38    46        INIT_FCALL                                               'range'
         47        SEND_VAL                                                 0
         48        COUNT                                            ~32     !4
         49        SUB                                              ~33     ~32, 1
         50        SEND_VAL                                                 ~33
         51        DO_ICALL                                         $34     
         52      > FE_RESET_R                                       $35     $34, ->59
         53    > > FE_FETCH_R                                               $35, !9, ->59
   39    54    >   FETCH_DIM_R                                      ~37     !6, !9
         55        FETCH_DIM_R                                      ~36     !4, !9
         56        FETCH_DIM_R                                      ~38     ~36, ~37
         57        ASSIGN_OP                                     8          !8, ~38
   38    58      > JMP                                                      ->53
         59    >   FE_FREE                                                  $35
   42    60        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FVOtvl%3A42%240'
         61        BIND_LEXICAL                                             ~40, !6
         62        BIND_LEXICAL                                             ~40, !4
         63        ASSIGN                                                   !10, ~40
   59    64        INIT_DYNAMIC_CALL                                        !10
         65        DO_FCALL                                      0  $42     
         66        BOOL_NOT                                         ~43     $42
         67      > JMPZ                                                     ~43, ->71
   60    68    >   ASSIGN_DIM                                               !7
         69        OP_DATA                                                  !8
         70      > JMP                                                      ->72
   62    71    > > JMP                                                      ->73
   33    72    > > JMPNZ                                                    <true>, ->45
   65    73    > > RETURN                                                   !7
   66    74*     > RETURN                                                   null

End of function checkcase

Function %00%7Bclosure%7D%2Fin%2FVOtvl%3A42%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 34
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 34
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 33
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 31
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 31
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/VOtvl
function name:  {closure}
number of ops:  37
compiled vars:  !0 = $flags, !1 = $element, !2 = $i, !3 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   BIND_STATIC                                              !0
          1        BIND_STATIC                                              !1
   43     2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 0
          4        COUNT                                            ~4      !0
          5        SUB                                              ~5      ~4, 1
          6        SEND_VAL                                                 ~5
          7        DO_ICALL                                         $6      
          8      > FE_RESET_R                                       $7      $6, ->34
          9    > > FE_FETCH_R                                               $7, !2, ->34
   45    10    >   FETCH_DIM_R                                      ~8      !0, !2
         11        FETCH_DIM_R                                      ~9      !1, !2
         12        COUNT                                            ~10     ~9
         13        SUB                                              ~11     ~10, 1
         14        IS_SMALLER                                               ~8, ~11
         15      > JMPZ                                                     ~12, ->33
   47    16    >   FETCH_DIM_RW                                     $13     !0, !2
         17        PRE_INC                                                  $13
   49    18        IS_SMALLER                                               0, !2
         19      > JMPZ                                                     ~15, ->31
   50    20    >   INIT_FCALL                                               'range'
         21        SEND_VAL                                                 0
         22        SUB                                              ~16     !2, 1
         23        SEND_VAL                                                 ~16
         24        DO_ICALL                                         $17     
         25      > FE_RESET_R                                       $18     $17, ->30
         26    > > FE_FETCH_R                                               $18, !3, ->30
   51    27    >   ASSIGN_DIM                                               !0, !3
         28        OP_DATA                                                  0
   50    29      > JMP                                                      ->26
         30    >   FE_FREE                                                  $18
   53    31    >   FE_FREE                                                  $7
         32      > RETURN                                                   <false>
   43    33    > > JMP                                                      ->9
         34    >   FE_FREE                                                  $7
   56    35      > RETURN                                                   <true>
   57    36*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FVOtvl%3A42%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.9 ms | 1411 KiB | 29 Q