3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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"); ?>
Output for 5.4.0 - 7.1.0
a = aaa,b = bbb Notice: Array to string conversion in /in/EIWv2 on line 5 matrix=Array Notice: Array to string conversion in /in/EIWv2 on line 8 matrix[0]=Array Notice: Array to string conversion in /in/EIWv2 on line 8 matrix[1]=Array1
Output for 4.3.0 - 5.3.29
a = aaa,b = bbbmatrix=Arraymatrix[0]=Arraymatrix[1]=Array1