3v4l.org

run code in 500+ PHP versions simultaneously
<?php function str_intersection($str1, $str2) { [$long, $short] = strlen($str1) > strlen($str2) ? [$str1, $str2] : [$str2, $str1]; $shortLength = strlen($short); for ($length = $shortLength; $length > 0; $length--) { for ($offset = 0; $offset < $shortLength - 1; $offset++) { if (strpos($long, substr($short, $offset, $length)) !== false) return $length; } } return 0; } $str1 = "lorem ipsum"; $str2 = "rem"; echo str_intersection($str1, $str2) . PHP_EOL; // Expected result: 3 $str2 = "xzy"; echo str_intersection($str1, $str2) . PHP_EOL; // Expected result: 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7YW0R
function name:  (null)
number of ops:  16
compiled vars:  !0 = $str1, !1 = $str2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                       !0, 'lorem+ipsum'
   16     1        ASSIGN                                                       !1, 'rem'
   17     2        INIT_FCALL                                                   'str_intersection'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0  $4      
          6        CONCAT                                               ~5      $4, '%0A'
          7        ECHO                                                         ~5
   19     8        ASSIGN                                                       !1, 'xzy'
   20     9        INIT_FCALL                                                   'str_intersection'
         10        SEND_VAR                                                     !0
         11        SEND_VAR                                                     !1
         12        DO_FCALL                                          0  $7      
         13        CONCAT                                               ~8      $7, '%0A'
         14        ECHO                                                         ~8
         15      > RETURN                                                       1

Function str_intersection:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 22
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 24
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 22
Branch analysis from position: 37
Branch analysis from position: 22
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 24
Branch analysis from position: 34
Branch analysis from position: 24
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
filename:       /in/7YW0R
function name:  str_intersection
number of ops:  39
compiled vars:  !0 = $str1, !1 = $str2, !2 = $long, !3 = $short, !4 = $shortLength, !5 = $length, !6 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        STRLEN                                               ~7      !0
          3        STRLEN                                               ~8      !1
          4        IS_SMALLER                                                   ~8, ~7
          5      > JMPZ                                                         ~9, ->10
          6    >   INIT_ARRAY                                           ~10     !0
          7        ADD_ARRAY_ELEMENT                                    ~10     !1
          8        QM_ASSIGN                                            ~11     ~10
          9      > JMP                                                          ->13
         10    >   INIT_ARRAY                                           ~12     !1
         11        ADD_ARRAY_ELEMENT                                    ~12     !0
         12        QM_ASSIGN                                            ~11     ~12
         13    >   FETCH_LIST_R                                         $13     ~11, 0
         14        ASSIGN                                                       !2, $13
         15        FETCH_LIST_R                                         $15     ~11, 1
         16        ASSIGN                                                       !3, $15
         17        FREE                                                         ~11
    6    18        STRLEN                                               ~17     !3
         19        ASSIGN                                                       !4, ~17
    7    20        ASSIGN                                                       !5, !4
         21      > JMP                                                          ->35
    8    22    >   ASSIGN                                                       !6, 0
         23      > JMP                                                          ->31
    9    24    >   FRAMELESS_ICALL_3                substr              ~21     !3, !6
         25        OP_DATA                                                      !5
         26        FRAMELESS_ICALL_2                strpos              ~22     !2, ~21
         27        TYPE_CHECK                                      1018          ~22
         28      > JMPZ                                                         ~23, ->30
         29    > > RETURN                                                       !5
    8    30    >   PRE_INC                                                      !6
         31    >   SUB                                                  ~25     !4, 1
         32        IS_SMALLER                                                   !6, ~25
         33      > JMPNZ                                                        ~26, ->24
    7    34    >   PRE_DEC                                                      !5
         35    >   IS_SMALLER                                                   0, !5
         36      > JMPNZ                                                        ~28, ->22
   12    37    > > RETURN                                                       0
   13    38*     > RETURN                                                       null

End of function str_intersection

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.17 ms | 1461 KiB | 15 Q