3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildRegexFrom(string $word): string { // Split word to letters $letters = str_split($word); // Creating all side of alternations in our regex foreach ($letters as $key => $letter) if (end($letters) != $letter) $regex[] = "$letter(?={$letters[$key + 1]})|(?<=$letter){$letters[$key + 1]}"; // Return whole cooked pattern return "~(?|((?>".implode('|', $regex).")+)|([$word]))~i"; } function longestSubstring(array $array, string $regex): array { foreach ($array as $value) { preg_match_all($regex, $value, $matches); usort($matches[1], function($a, $b) { return strlen($b) <=> strlen($a); }); // Store longest match being sorted $substrings[] = $matches[1][0]; } return $substrings; } print_r(longestSubstring(['Mymaxmuis', 'axmuis', 'muster'], buildRegexFrom('maxmuster')));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7GOk3
function name:  (null)
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'longestsubstring'
          2        SEND_VAL                                                 <array>
          3        INIT_FCALL                                               'buildregexfrom'
          4        SEND_VAL                                                 'maxmuster'
          5        DO_FCALL                                      0  $0      
          6        SEND_VAR                                                 $0
          7        DO_FCALL                                      0  $1      
          8        SEND_VAR                                                 $1
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function buildregexfrom:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/7GOk3
function name:  buildRegexFrom
number of ops:  41
compiled vars:  !0 = $word, !1 = $letters, !2 = $letter, !3 = $key, !4 = $regex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'str_split'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
    7     5      > FE_RESET_R                                       $7      !1, ->27
          6    > > FE_FETCH_R                                       ~8      $7, !2, ->27
          7    >   ASSIGN                                                   !3, ~8
    8     8        INIT_FCALL                                               'end'
          9        SEND_REF                                                 !1
         10        DO_ICALL                                         $10     
         11        IS_NOT_EQUAL                                             !2, $10
         12      > JMPZ                                                     ~11, ->26
    9    13    >   ROPE_INIT                                     7  ~18     !2
         14        ROPE_ADD                                      1  ~18     ~18, '%28%3F%3D'
         15        ADD                                              ~13     !3, 1
         16        FETCH_DIM_R                                      ~14     !1, ~13
         17        ROPE_ADD                                      2  ~18     ~18, ~14
         18        ROPE_ADD                                      3  ~18     ~18, '%29%7C%28%3F%3C%3D'
         19        ROPE_ADD                                      4  ~18     ~18, !2
         20        ROPE_ADD                                      5  ~18     ~18, '%29'
         21        ADD                                              ~15     !3, 1
         22        FETCH_DIM_R                                      ~16     !1, ~15
         23        ROPE_END                                      6  ~17     ~18, ~16
         24        ASSIGN_DIM                                               !4
         25        OP_DATA                                                  ~17
    7    26    > > JMP                                                      ->6
         27    >   FE_FREE                                                  $7
   11    28        INIT_FCALL                                               'implode'
         29        SEND_VAL                                                 '%7C'
         30        SEND_VAR                                                 !4
         31        DO_ICALL                                         $22     
         32        CONCAT                                           ~23     '%7E%28%3F%7C%28%28%3F%3E', $22
         33        ROPE_INIT                                     3  ~25     '%29%2B%29%7C%28%5B'
         34        ROPE_ADD                                      1  ~25     ~25, !0
         35        ROPE_END                                      2  ~24     ~25, '%5D%29%29%7Ei'
         36        CONCAT                                           ~27     ~23, ~24
         37        VERIFY_RETURN_TYPE                                       ~27
         38      > RETURN                                                   ~27
   12    39*       VERIFY_RETURN_TYPE                                       
         40*     > RETURN                                                   null

End of function buildregexfrom

Function longestsubstring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 20
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/7GOk3
function name:  longestSubstring
number of ops:  25
compiled vars:  !0 = $array, !1 = $regex, !2 = $value, !3 = $matches, !4 = $substrings
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2      > FE_RESET_R                                       $5      !0, ->20
          3    > > FE_FETCH_R                                               $5, !2, ->20
   16     4    >   INIT_FCALL                                               'preg_match_all'
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        SEND_REF                                                 !3
          8        DO_ICALL                                                 
   17     9        INIT_FCALL                                               'usort'
         10        FETCH_DIM_W                                      $7      !3, 1
         11        SEND_REF                                                 $7
         12        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
   19    13        SEND_VAL                                                 ~8
   17    14        DO_ICALL                                                 
   21    15        FETCH_DIM_R                                      ~11     !3, 1
         16        FETCH_DIM_R                                      ~12     ~11, 0
         17        ASSIGN_DIM                                               !4
         18        OP_DATA                                                  ~12
   15    19      > JMP                                                      ->3
         20    >   FE_FREE                                                  $5
   24    21        VERIFY_RETURN_TYPE                                       !4
         22      > RETURN                                                   !4
   25    23*       VERIFY_RETURN_TYPE                                       
         24*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7GOk3
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        STRLEN                                           ~2      !1
          3        STRLEN                                           ~3      !0
          4        SPACESHIP                                        ~4      ~2, ~3
          5      > RETURN                                                   ~4
   19     6*     > RETURN                                                   null

End of Dynamic Function 0

End of function longestsubstring

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.86 ms | 1019 KiB | 21 Q