3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function LevenshteinDistance($str1, $str2) { $d = array (); $len1 = strlen($str1); $len2 = strlen($str2); for ($i1 = 0; $i1 <= $len1; $i1++) { $d[$i1] = array (); $d[$i1][0] = $i1; } for ($i2 = 0; $i2 <= $len2; $i2++) { $d[0][$i2] = $i2; } for ($i1 = 1; $i1 <= $len1; $i1++) { for ($i2 = 1; $i2 <= $len2; $i2++) { $cost = ($str1[$i1 - 1] == $str2[$i2 - 1]) ? 0 : 1; $d[$i1][$i2] = min( $d[$i1 - 1][$i2 ] + 1, //挿入 $d[$i1 ][$i2 - 1] + 1, //削除 $d[$i1 - 1][$i2 - 1] + $cost //置換 ); } } return $d[$len1][$len2]; } echo LevenshteinDistance("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","qwertyuioasdfghjklzxcvbnmfghjkyudfghjkcvbnmqwertyudfghjxcvbnqwertyuioplkjhgfdsamnbcvbhfeghipnvcseaaaaaaaaaaaaaaaaaaaaaaaaafjjuuuuuuuuuuuuuuuuuuuuuihkhjyftytdtvjhbkjnklklnbvvvvvvvvvhvhgzredyvjkjhiohiguyygjpojohuihuybhjmnknklnlkbhjcgcgcjhblk;lkoiouigjggggggggggggggggggggggggggggggggggggggggggggggggggg").<br>; echo levenshtein("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","qwertyuioasdfghjklzxcvbnmfghjkyudfghjkcvbnmqwertyudfghjxcvbnqwertyuioplkjhgfdsamnbcvbhfeghipnvcseaaaaaaaaaaaaaaaaaaaaaaaaafjjuuuuuuuuuuuuuuuuuuuuuihkhjyftytdtvjhbkjnklklnbvvvvvvvvvhvhgzredyvjkjhiohiguyygjpojohuihuybhjmnknklnlkbhjcgcgcjhblk;lkoiouigjggggggggggggggggggggggggggggggggggggggggggggggggggg"); ?>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.4.28
Parse error: syntax error, unexpected '<' in /in/QNb6q on line 27
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '<' in /in/QNb6q on line 27
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/QNb6q on line 27
Process exited with code 255.