3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function edit_distance_ond($str1 ,$str2){ $array = array(); $x = 0; $y = 0; $offset = strlen($str1); $array[$offset + 1] = 0; for($D = 0; $D <= strlen($str1) + strlen($str2); $D++){ //echo $D." "; for($k = -$D; $k <= $D; $k += 2){ if($k == -$D || $k != $D && $array[$k-1+$offset] < $array[$k+1+$offset]) $x = $array[$k+1+$offset]; else $x = $array[$k-1+$offset] + 1; $y = $x - $k; while($x < strlen($str1) && $y < strlen($str2) && $str1[$x] == $str2[$y]){ $x++; $y++; } $array[$k+$offset] = $x; if($x >= strlen($str1) && $y >= strlen($str2)) return $D; } } return -1; } $a = "kitten"; $b = "sitting"; $edo = edit_distance_ond($a,$b); echo $edo; ?>
Output for 4.3.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
5
Output for hhvm-3.10.0

Process exited with code 153.