3v4l.org

run code in 300+ PHP versions simultaneously
<?php function similarity($str1, $str2) { $len1 = strlen($str1); $len2 = strlen($str2); $max = max($len1, $len2); $similarity = $i = $j = 0; while (($i < $len1) && isset($str2[$j])) { if ($str1[$i] == $str2[$j]) { $similarity++; $i++; $j++; } elseif ($len1 < $len2) { $len1++; $j++; } elseif ($len1 > $len2) { $i++; $len1--; } else { $i++; $j++; } } return round($similarity / $max, 2); } $str1 = '12345678901234567890'; $str2 = '12345678991234567890'; echo 'Similarity: ' . (similarity($str1, $str2) * 100) . '%'; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JUlj4
function name:  (null)
number of ops:  11
compiled vars:  !0 = $str1, !1 = $str2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, '12345678901234567890'
   31     1        ASSIGN                                                   !1, '12345678991234567890'
   33     2        INIT_FCALL                                               'similarity'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        MUL                                              ~5      $4, 100
          7        CONCAT                                           ~6      'Similarity%3A+', ~5
          8        CONCAT                                           ~7      ~6, '%25'
          9        ECHO                                                     ~7
   34    10      > RETURN                                                   1

Function similarity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 15
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 33
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
Branch analysis from position: 39
Branch analysis from position: 39
filename:       /in/JUlj4
function name:  similarity
number of ops:  47
compiled vars:  !0 = $str1, !1 = $str2, !2 = $len1, !3 = $len2, !4 = $max, !5 = $similarity, !6 = $i, !7 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        STRLEN                                           ~8      !0
          3        ASSIGN                                                   !2, ~8
    5     4        STRLEN                                           ~10     !1
          5        ASSIGN                                                   !3, ~10
    7     6        INIT_FCALL                                               'max'
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $12     
         10        ASSIGN                                                   !4, $12
    8    11        ASSIGN                                           ~14     !7, 0
         12        ASSIGN                                           ~15     !6, ~14
         13        ASSIGN                                                   !5, ~15
   10    14      > JMP                                                      ->35
   11    15    >   FETCH_DIM_R                                      ~17     !0, !6
         16        FETCH_DIM_R                                      ~18     !1, !7
         17        IS_EQUAL                                                 ~17, ~18
         18      > JMPZ                                                     ~19, ->23
   12    19    >   PRE_INC                                                  !5
   13    20        PRE_INC                                                  !6
   14    21        PRE_INC                                                  !7
         22      > JMP                                                      ->35
   15    23    >   IS_SMALLER                                               !2, !3
         24      > JMPZ                                                     ~23, ->28
   16    25    >   PRE_INC                                                  !2
   17    26        PRE_INC                                                  !7
         27      > JMP                                                      ->35
   18    28    >   IS_SMALLER                                               !3, !2
         29      > JMPZ                                                     ~26, ->33
   19    30    >   PRE_INC                                                  !6
   20    31        PRE_DEC                                                  !2
         32      > JMP                                                      ->35
   22    33    >   PRE_INC                                                  !6
   23    34        PRE_INC                                                  !7
   10    35    >   IS_SMALLER                                       ~31     !6, !2
         36      > JMPZ_EX                                          ~31     ~31, ->39
         37    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~32     !1, !7
         38        BOOL                                             ~31     ~32
         39    > > JMPNZ                                                    ~31, ->15
   27    40    >   INIT_FCALL                                               'round'
         41        DIV                                              ~33     !5, !4
         42        SEND_VAL                                                 ~33
         43        SEND_VAL                                                 2
         44        DO_ICALL                                         $34     
         45      > RETURN                                                   $34
   28    46*     > RETURN                                                   null

End of function similarity

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.66 ms | 1407 KiB | 18 Q