3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function snake($k,$y,$str1,$str2){ $x = $y - $k; while($x < mb_strlen($str1) && $y < mb_strlen($str2) && $str1[$x] == $str2[$y]){ $x++; $y++; } return $y; } function edit_distance_onp($str1, $str2){ $s1 = mb_strlen($str1) > mb_strlen($str2) ? $str2 : $str1; $s2 = mb_strlen($str1) > mb_strlen($str2) ? $str1 : $str2; $fp = array(); $x = 0; $y = 0; $k = 0; $p = 0; $offset = mb_strlen($s1) + 1; $delta = mb_strlen($s2) - mb_strlen($s1); for ($i = 0; $i < SIZE; $i++) $fp[$i] = -1; for ($p = 0; $fp[$delta + $offset] != mb_strlen($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 = "aaa"; $cha2 = "bbb"; echo edit_distance_onp($cha1,$cha2); ?>
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Use of undefined constant SIZE - assumed 'SIZE' in /in/FM403 on line 20 Notice: Undefined offset: 4 in /in/FM403 on line 22 Notice: Undefined offset: 3 in /in/FM403 on line 27 Notice: Undefined offset: 5 in /in/FM403 on line 27 Notice: Undefined offset: 2 in /in/FM403 on line 24 Notice: Undefined offset: 6 in /in/FM403 on line 26 Notice: Undefined offset: 1 in /in/FM403 on line 24 Notice: Undefined offset: 7 in /in/FM403 on line 26 4
Output for hhvm-3.10.0 - 3.12.0
Notice: Use of undefined constant SIZE - assumed 'SIZE' in /in/FM403 on line 20 Notice: Undefined index: 4 in /in/FM403 on line 22 Notice: Undefined index: 3 in /in/FM403 on line 27 Notice: Undefined index: 5 in /in/FM403 on line 27 Notice: Undefined index: 2 in /in/FM403 on line 24 Notice: Undefined index: 6 in /in/FM403 on line 26 Notice: Undefined index: 1 in /in/FM403 on line 24 Notice: Undefined index: 7 in /in/FM403 on line 26 4
Output for 4.3.0 - 5.2.17
Notice: Use of undefined constant SIZE - assumed 'SIZE' in /in/FM403 on line 20 Notice: Undefined offset: 4 in /in/FM403 on line 22 Notice: Undefined offset: 3 in /in/FM403 on line 27 Notice: Undefined offset: 5 in /in/FM403 on line 27 Notice: Undefined offset: 2 in /in/FM403 on line 24 Notice: Undefined offset: 6 in /in/FM403 on line 26 Notice: Undefined offset: 1 in /in/FM403 on line 24 Notice: Undefined offset: 7 in /in/FM403 on line 26 4