3v4l.org

run code in 300+ PHP versions simultaneously
<?php function snake($k,$y,$str1,$str2){ $x = $y - $k; while($x < count($str1) && $y < count($str2) && $str1[$x] == $str2[$y]){ $x++; $y++; } return $y; } function edit_distance_onp($str1, $str2){ $s1 = count($str1) > count($str2) ? $str2 : $str1; $s2 = count($str1) > count($str2) ? $str1 : $str2; $fp = array(); $x = 0; $y = 0; $k = 0; $p = 0; $offset = count($s1) + 1; $delta = count($s2) - count($s1); for ($i = 0; $i < 15; $i++) $fp[$i] = -1; for ($p = 0; $fp[$delta + $offset] != count($s2); $p++) { for($k = -$p; $k < $delta; $k++) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); for($k = $delta + $p; $k > $delta; $k--) $fp[$k + $offset] = snake($k, max($fp[$k-1+$offset] + 1, $fp[$k+1+$offset]), $s1, $s2); $fp[$delta + $offset] = snake($delta, max($fp[$delta-1+$offset] + 1, $fp[$delta+1+$offset]), $s1, $s2); } return $delta + ($p - 1) * 2; } $cha1[0] = "aaa"; $cha1[1] = "bbb"; $cha1[2] = "ccc"; $cha2[0] = "ddd"; $cha2[1] = "eee"; $cha2[2] = "fff"; echo edit_distance_onp($cha1,$cha2); ?>
Output for git.master, git.master_jit, rfc.property-hooks
6

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:
34.47 ms | 401 KiB | 8 Q