# 3v4l.org

run code in 200+ php & hhvm versions
<?php function levenshteinDistance(\$a, \$b) { echo("a = ".\$a.",b = ".\$b); \$matrix = array(count(\$a) + 1); echo("matrix=".\$matrix); for (\$i=0; \$i<count(\$a)+1; \$i++) { \$matrix[\$i] = array(count(\$b) + 1); echo("matrix[".\$i."]=".\$matrix[\$i]); } for (\$i=0; \$i<count(\$a)+1; \$i++) { \$matrix[\$i][0] = \$i; } for (\$j=0; \$j<count(\$b)+1; \$j++) { \$matrix[0][\$j] = \$j; } for (\$i=1; \$i<count(\$a)+1; \$i++) { for (\$j=1; \$j<count(\$b)+1; \$j++) { //\$x = \$a[\$i - 1] == \$b[\$j -1] ? 0 : 1; if(\$a[\$i-1] == \$b[\$j-1]){ \$x = 0; } else{ \$x = 1; } \$matrix[\$i][\$j] = min( \$matrix[\$i - 1][\$j] + 1, \$matrix[\$i][\$j - 1] + 1, \$matrix[\$i - 1][\$j- 1] + \$x ); } } return \$matrix[count(\$a)][count(\$b)]; } echo levenshteinDistance("aaa","bbb"); ?>
Output for 7.2.0
a = aaa,b = bbb Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 4 Notice: Array to string conversion in /in/EIWv2 on line 5 matrix=Array Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 6 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 7 Notice: Array to string conversion in /in/EIWv2 on line 8 matrix[0]=Array Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 6 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 7 Notice: Array to string conversion in /in/EIWv2 on line 8 matrix[1]=Array Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 6 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 10 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 10 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 10 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 13 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 13 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 13 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 16 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 17 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 17 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 16 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 32 Warning: count(): Parameter must be an array or an object that implements Countable in /in/EIWv2 on line 32 1
Output for 5.4.0 - 7.1.10
a = aaa,b = bbb Notice: Array to string conversion in /in/EIWv2 on line 5 matrix=Array Notice: Array to string conversion in /in/EIWv2 on line 8 matrix[0]=Array Notice: Array to string conversion in /in/EIWv2 on line 8 matrix[1]=Array1
Output for 4.3.0 - 5.3.29
a = aaa,b = bbbmatrix=Arraymatrix[0]=Arraymatrix[1]=Array1