3v4l.org

run code in 300+ PHP versions simultaneously
<?php function LevenshteinDistance($str1, $str2) { $d = array (); $len1 = mb_strlen($str1); $len2 = mb_strlen($str2); for ($i1 = 0; $i1 <= $len1; $i1++) { $d[$i1] = array (); $d[$i1][0] = $i1; } for ($i2 = 0; $i2 <= $len2; $i2++) { $d[0][$i2] = $i2; } for ($i1 = 1; $i1 <= $len1; $i1++) { for ($i2 = 1; $i2 <= $len2; $i2++) { $cost = ($str1[$i1 - 1] == $str2[$i2 - 1]) ? 0 : 1; $d[$i1][$i2] = min( $d[$i1 - 1][$i2 ] + 1, //挿入 $d[$i1 ][$i2 - 1] + 1, //削除 $d[$i1 - 1][$i2 - 1] + $cost //置換 ); } } return $d[$len1][$len2]; } echo LevenshteinDistance("こんにちは","こんにちわ"); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4S0WG
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_FCALL                                               'levenshteindistance'
          1        SEND_VAL                                                 '%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF'
          2        SEND_VAL                                                 '%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%82%8F'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   26     5      > RETURN                                                   1

Function levenshteindistance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 13
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 23
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 31
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 33
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 70, Position 2 = 31
Branch analysis from position: 70
Branch analysis from position: 31
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 33
Branch analysis from position: 67
Branch analysis from position: 33
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 67, Position 2 = 33
Branch analysis from position: 67
Branch analysis from position: 33
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 23
Branch analysis from position: 29
Branch analysis from position: 23
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 13
Branch analysis from position: 21
Branch analysis from position: 13
filename:       /in/4S0WG
function name:  LevenshteinDistance
number of ops:  74
compiled vars:  !0 = $str1, !1 = $str2, !2 = $d, !3 = $len1, !4 = $len2, !5 = $i1, !6 = $i2, !7 = $cost
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    4     3        INIT_FCALL                                               'mb_strlen'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !3, $9
    5     7        INIT_FCALL                                               'mb_strlen'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !4, $11
    6    11        ASSIGN                                                   !5, 0
         12      > JMP                                                      ->19
    7    13    >   ASSIGN_DIM                                               !2, !5
         14        OP_DATA                                                  <array>
    8    15        FETCH_DIM_W                                      $15     !2, !5
         16        ASSIGN_DIM                                               $15, 0
         17        OP_DATA                                                  !5
    6    18        PRE_INC                                                  !5
         19    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         20      > JMPNZ                                                    ~18, ->13
   10    21    >   ASSIGN                                                   !6, 0
         22      > JMP                                                      ->27
   11    23    >   FETCH_DIM_W                                      $20     !2, 0
         24        ASSIGN_DIM                                               $20, !6
         25        OP_DATA                                                  !6
   10    26        PRE_INC                                                  !6
         27    >   IS_SMALLER_OR_EQUAL                                      !6, !4
         28      > JMPNZ                                                    ~23, ->23
   13    29    >   ASSIGN                                                   !5, 1
         30      > JMP                                                      ->68
   14    31    >   ASSIGN                                                   !6, 1
         32      > JMP                                                      ->65
   15    33    >   SUB                                              ~26     !5, 1
         34        FETCH_DIM_R                                      ~27     !0, ~26
         35        SUB                                              ~28     !6, 1
         36        FETCH_DIM_R                                      ~29     !1, ~28
         37        IS_EQUAL                                                 ~27, ~29
         38      > JMPZ                                                     ~30, ->41
         39    >   QM_ASSIGN                                        ~31     0
         40      > JMP                                                      ->42
         41    >   QM_ASSIGN                                        ~31     1
         42    >   ASSIGN                                                   !7, ~31
   16    43        INIT_FCALL                                               'min'
   17    44        SUB                                              ~35     !5, 1
         45        FETCH_DIM_R                                      ~36     !2, ~35
         46        FETCH_DIM_R                                      ~37     ~36, !6
         47        ADD                                              ~38     ~37, 1
         48        SEND_VAL                                                 ~38
   18    49        SUB                                              ~40     !6, 1
         50        FETCH_DIM_R                                      ~39     !2, !5
         51        FETCH_DIM_R                                      ~41     ~39, ~40
         52        ADD                                              ~42     ~41, 1
         53        SEND_VAL                                                 ~42
   19    54        SUB                                              ~43     !5, 1
         55        SUB                                              ~45     !6, 1
         56        FETCH_DIM_R                                      ~44     !2, ~43
         57        FETCH_DIM_R                                      ~46     ~44, ~45
         58        ADD                                              ~47     ~46, !7
         59        SEND_VAL                                                 ~47
         60        DO_ICALL                                         $48     
   16    61        FETCH_DIM_W                                      $33     !2, !5
         62        ASSIGN_DIM                                               $33, !6
   19    63        OP_DATA                                                  $48
   14    64        PRE_INC                                                  !6
         65    >   IS_SMALLER_OR_EQUAL                                      !6, !4
         66      > JMPNZ                                                    ~50, ->33
   13    67    >   PRE_INC                                                  !5
         68    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         69      > JMPNZ                                                    ~52, ->31
   23    70    >   FETCH_DIM_R                                      ~53     !2, !3
         71        FETCH_DIM_R                                      ~54     ~53, !4
         72      > RETURN                                                   ~54
   24    73*     > RETURN                                                   null

End of function levenshteindistance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.5 ms | 1407 KiB | 18 Q