3v4l.org

run code in 300+ PHP versions simultaneously
<?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++){ 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 = "test"; $b = "test2"; $edo = edit_distance_ond($a,$b); echo $edo; ?>
Output for git.master, git.master_jit, rfc.property-hooks
1

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.24 ms | 401 KiB | 8 Q