3v4l.org

run code in 300+ 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 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 22
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 24
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 22
Branch analysis from position: 43
Branch analysis from position: 22
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 24
Branch analysis from position: 40
Branch analysis from position: 24
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
filename:       /in/7YW0R
function name:  str_intersection
number of ops:  45
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                                                      ->41
    8    22    >   ASSIGN                                                   !6, 0
         23      > JMP                                                      ->37
    9    24    >   INIT_FCALL                                               'strpos'
         25        SEND_VAR                                                 !2
         26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !3
         28        SEND_VAR                                                 !6
         29        SEND_VAR                                                 !5
         30        DO_ICALL                                         $21     
         31        SEND_VAR                                                 $21
         32        DO_ICALL                                         $22     
         33        TYPE_CHECK                                  1018          $22
         34      > JMPZ                                                     ~23, ->36
         35    > > RETURN                                                   !5
    8    36    >   PRE_INC                                                  !6
         37    >   SUB                                              ~25     !4, 1
         38        IS_SMALLER                                               !6, ~25
         39      > JMPNZ                                                    ~26, ->24
    7    40    >   PRE_DEC                                                  !5
         41    >   IS_SMALLER                                               0, !5
         42      > JMPNZ                                                    ~28, ->22
   12    43    > > RETURN                                                   0
   13    44*     > RETURN                                                   null

End of function str_intersection

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.41 ms | 1407 KiB | 19 Q