3v4l.org

run code in 300+ PHP versions simultaneously
<?php function levenshteinDistance($a, $b) { $matrix = array(count($a) + 1); for ($i=0; $i<count($a)+1; $i++) { $matrix[$i] = array(count($b) + 1); } for ($i=0; $i<count($a)+1; $i++) { $matrix[$i][0] = $i; } for ($j=0; $j<count($b)+1; $j++) { $matrix[0][$j] = $j; } for ($i=1; $i<count($a)+1; $i++) { for ($j=1; $j<count($b)+1; $j++) { //$x = $a[$i - 1] == $b[$j -1] ? 0 : 1; if($a[$i-1] == $b[$j-1]){ $x = 0; } else{ $x = 1; } $matrix[$i][$j] = min( $matrix[$i - 1][$j] + 1, $matrix[$i][$j - 1] + 1, $matrix[$i - 1][$j- 1] + $x ); } } return $matrix[count($a)][count($b)]; } echo levenshteinDistance("aqq","att"); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FQfJX
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_FCALL                                               'levenshteindistance'
          1        SEND_VAL                                                 'aqq'
          2        SEND_VAL                                                 'att'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   32     5      > RETURN                                                   1

Function levenshteindistance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 8
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 20
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 30
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 40
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 42
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 82, Position 2 = 40
Branch analysis from position: 82
Branch analysis from position: 40
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 42
Branch analysis from position: 77
Branch analysis from position: 42
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 42
Branch analysis from position: 77
Branch analysis from position: 42
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 30
Branch analysis from position: 38
Branch analysis from position: 30
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 20
Branch analysis from position: 28
Branch analysis from position: 20
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 8
Branch analysis from position: 18
Branch analysis from position: 8
filename:       /in/FQfJX
function name:  levenshteinDistance
number of ops:  88
compiled vars:  !0 = $a, !1 = $b, !2 = $matrix, !3 = $i, !4 = $j, !5 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        COUNT                                            ~6      !0
          3        ADD                                              ~7      ~6, 1
          4        INIT_ARRAY                                       ~8      ~7
          5        ASSIGN                                                   !2, ~8
    4     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->14
    5     8    >   COUNT                                            ~12     !1
          9        ADD                                              ~13     ~12, 1
         10        INIT_ARRAY                                       ~14     ~13
         11        ASSIGN_DIM                                               !2, !3
         12        OP_DATA                                                  ~14
    4    13        PRE_INC                                                  !3
         14    >   COUNT                                            ~16     !0
         15        ADD                                              ~17     ~16, 1
         16        IS_SMALLER                                               !3, ~17
         17      > JMPNZ                                                    ~18, ->8
    7    18    >   ASSIGN                                                   !3, 0
         19      > JMP                                                      ->24
    8    20    >   FETCH_DIM_W                                      $20     !2, !3
         21        ASSIGN_DIM                                               $20, 0
         22        OP_DATA                                                  !3
    7    23        PRE_INC                                                  !3
         24    >   COUNT                                            ~23     !0
         25        ADD                                              ~24     ~23, 1
         26        IS_SMALLER                                               !3, ~24
         27      > JMPNZ                                                    ~25, ->20
   10    28    >   ASSIGN                                                   !4, 0
         29      > JMP                                                      ->34
   11    30    >   FETCH_DIM_W                                      $27     !2, 0
         31        ASSIGN_DIM                                               $27, !4
         32        OP_DATA                                                  !4
   10    33        PRE_INC                                                  !4
         34    >   COUNT                                            ~30     !1
         35        ADD                                              ~31     ~30, 1
         36        IS_SMALLER                                               !4, ~31
         37      > JMPNZ                                                    ~32, ->30
   13    38    >   ASSIGN                                                   !3, 1
         39      > JMP                                                      ->78
   14    40    >   ASSIGN                                                   !4, 1
         41      > JMP                                                      ->73
   16    42    >   SUB                                              ~35     !3, 1
         43        FETCH_DIM_R                                      ~36     !0, ~35
         44        SUB                                              ~37     !4, 1
         45        FETCH_DIM_R                                      ~38     !1, ~37
         46        IS_EQUAL                                                 ~36, ~38
         47      > JMPZ                                                     ~39, ->50
   17    48    >   ASSIGN                                                   !5, 0
         49      > JMP                                                      ->51
   20    50    >   ASSIGN                                                   !5, 1
   22    51    >   INIT_FCALL                                               'min'
   23    52        SUB                                              ~44     !3, 1
         53        FETCH_DIM_R                                      ~45     !2, ~44
         54        FETCH_DIM_R                                      ~46     ~45, !4
         55        ADD                                              ~47     ~46, 1
         56        SEND_VAL                                                 ~47
   24    57        SUB                                              ~49     !4, 1
         58        FETCH_DIM_R                                      ~48     !2, !3
         59        FETCH_DIM_R                                      ~50     ~48, ~49
         60        ADD                                              ~51     ~50, 1
         61        SEND_VAL                                                 ~51
   25    62        SUB                                              ~52     !3, 1
         63        SUB                                              ~54     !4, 1
         64        FETCH_DIM_R                                      ~53     !2, ~52
         65        FETCH_DIM_R                                      ~55     ~53, ~54
         66        ADD                                              ~56     ~55, !5
         67        SEND_VAL                                                 ~56
         68        DO_ICALL                                         $57     
   22    69        FETCH_DIM_W                                      $42     !2, !3
         70        ASSIGN_DIM                                               $42, !4
   25    71        OP_DATA                                                  $57
   14    72        PRE_INC                                                  !4
         73    >   COUNT                                            ~59     !1
         74        ADD                                              ~60     ~59, 1
         75        IS_SMALLER                                               !4, ~60
         76      > JMPNZ                                                    ~61, ->42
   13    77    >   PRE_INC                                                  !3
         78    >   COUNT                                            ~63     !0
         79        ADD                                              ~64     ~63, 1
         80        IS_SMALLER                                               !3, ~64
         81      > JMPNZ                                                    ~65, ->40
   29    82    >   COUNT                                            ~66     !0
         83        COUNT                                            ~68     !1
         84        FETCH_DIM_R                                      ~67     !2, ~66
         85        FETCH_DIM_R                                      ~69     ~67, ~68
         86      > RETURN                                                   ~69
   30    87*     > RETURN                                                   null

End of function levenshteindistance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.52 ms | 1398 KiB | 16 Q