3v4l.org

run code in 300+ PHP versions simultaneously
<?php function LevenshteinDistance($str1, $str2) { $d = array (); $len1 = mb_strlen($str1,"UTF-8"); $len2 = mb_strlen($str2,"UTF-8"); 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/vqLWX
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 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 15
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 25
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 33
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 35
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 72, Position 2 = 33
Branch analysis from position: 72
Branch analysis from position: 33
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 43
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 35
Branch analysis from position: 69
Branch analysis from position: 35
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 35
Branch analysis from position: 69
Branch analysis from position: 35
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 25
Branch analysis from position: 31
Branch analysis from position: 25
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 15
Branch analysis from position: 23
Branch analysis from position: 15
filename:       /in/vqLWX
function name:  LevenshteinDistance
number of ops:  76
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        SEND_VAL                                                 'UTF-8'
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !3, $9
    5     8        INIT_FCALL                                               'mb_strlen'
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 'UTF-8'
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !4, $11
    6    13        ASSIGN                                                   !5, 0
         14      > JMP                                                      ->21
    7    15    >   ASSIGN_DIM                                               !2, !5
         16        OP_DATA                                                  <array>
    8    17        FETCH_DIM_W                                      $15     !2, !5
         18        ASSIGN_DIM                                               $15, 0
         19        OP_DATA                                                  !5
    6    20        PRE_INC                                                  !5
         21    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         22      > JMPNZ                                                    ~18, ->15
   10    23    >   ASSIGN                                                   !6, 0
         24      > JMP                                                      ->29
   11    25    >   FETCH_DIM_W                                      $20     !2, 0
         26        ASSIGN_DIM                                               $20, !6
         27        OP_DATA                                                  !6
   10    28        PRE_INC                                                  !6
         29    >   IS_SMALLER_OR_EQUAL                                      !6, !4
         30      > JMPNZ                                                    ~23, ->25
   13    31    >   ASSIGN                                                   !5, 1
         32      > JMP                                                      ->70
   14    33    >   ASSIGN                                                   !6, 1
         34      > JMP                                                      ->67
   15    35    >   SUB                                              ~26     !5, 1
         36        FETCH_DIM_R                                      ~27     !0, ~26
         37        SUB                                              ~28     !6, 1
         38        FETCH_DIM_R                                      ~29     !1, ~28
         39        IS_EQUAL                                                 ~27, ~29
         40      > JMPZ                                                     ~30, ->43
         41    >   QM_ASSIGN                                        ~31     0
         42      > JMP                                                      ->44
         43    >   QM_ASSIGN                                        ~31     1
         44    >   ASSIGN                                                   !7, ~31
   16    45        INIT_FCALL                                               'min'
   17    46        SUB                                              ~35     !5, 1
         47        FETCH_DIM_R                                      ~36     !2, ~35
         48        FETCH_DIM_R                                      ~37     ~36, !6
         49        ADD                                              ~38     ~37, 1
         50        SEND_VAL                                                 ~38
   18    51        SUB                                              ~40     !6, 1
         52        FETCH_DIM_R                                      ~39     !2, !5
         53        FETCH_DIM_R                                      ~41     ~39, ~40
         54        ADD                                              ~42     ~41, 1
         55        SEND_VAL                                                 ~42
   19    56        SUB                                              ~43     !5, 1
         57        SUB                                              ~45     !6, 1
         58        FETCH_DIM_R                                      ~44     !2, ~43
         59        FETCH_DIM_R                                      ~46     ~44, ~45
         60        ADD                                              ~47     ~46, !7
         61        SEND_VAL                                                 ~47
         62        DO_ICALL                                         $48     
   16    63        FETCH_DIM_W                                      $33     !2, !5
         64        ASSIGN_DIM                                               $33, !6
   19    65        OP_DATA                                                  $48
   14    66        PRE_INC                                                  !6
         67    >   IS_SMALLER_OR_EQUAL                                      !6, !4
         68      > JMPNZ                                                    ~50, ->35
   13    69    >   PRE_INC                                                  !5
         70    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         71      > JMPNZ                                                    ~52, ->33
   23    72    >   FETCH_DIM_R                                      ~53     !2, !3
         73        FETCH_DIM_R                                      ~54     ~53, !4
         74      > RETURN                                                   ~54
   24    75*     > RETURN                                                   null

End of function levenshteindistance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.3 ms | 1398 KiB | 18 Q