3v4l.org

run code in 300+ PHP versions simultaneously
<?php function levenshteinDistance($a, $b) { $matrix = array(count($a) + 1); for ($i=0; $i<count($a)+1; $i++) { $matrix[$i] = array(count($b) + 1); } 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("aqq","att"); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /in/FQfJX:3 Stack trace: #0 /in/FQfJX(31): levenshteinDistance('aqq', 'att') #1 {main} thrown in /in/FQfJX on line 3
Process exited with code 255.

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