3v4l.org

run code in 300+ PHP versions simultaneously
<?php function levenshteinDistance($a, $b) { echo("a = " + $a + ",b = " + $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("aaa","bbb"); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ai1p5
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'levenshteindistance'
          1        SEND_VAL                                                 'aaa'
          2        SEND_VAL                                                 'bbb'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   33     5      > RETURN                                                   1

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

End of function levenshteindistance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.08 ms | 1407 KiB | 16 Q