3v4l.org

run code in 300+ PHP versions simultaneously
<?php function levenshteinDistance($a, $b) { echo("a = ".$a.",b = ".$b); $matrix = array(count($a) + 1); echo("matrix=".$matrix); for ($i=0; $i<count($a)+1; $i++) { $matrix[$i] = array(count($b) + 1); echo("matrix[".$i."]=".$matrix[$i]); } 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/EIWv2
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_FCALL                                               'levenshteindistance'
          1        SEND_VAL                                                 'aaa'
          2        SEND_VAL                                                 'bbb'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   35     5      > RETURN                                                   1

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

End of function levenshteindistance

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.98 ms | 1407 KiB | 16 Q