3v4l.org

run code in 300+ PHP versions simultaneously
<?phpfunction match($desk, $word) { if($desk == "") return false; if($word == "") return true;  $w = $word[0]; $ws = substr($word, 1);  $pos = strpos($desk, $w); if($pos !== false) { return match(substr($desk, 0, $pos).substr($desk, $pos + 1), $ws); }  $pos = strpos($desk, '*'); if($pos !== false) { return match(substr($desk, 0, $pos).substr($desk, $pos + 1), $ws); }  return false;} function search($tokens, $dictionary) { $filter = function($word) use($tokens) { return match($tokens, $word); };  return array_filter($dictionary, $filter);} function prettyPrint($words) { $compareLength = function($a, $b) { return strlen($a) - strlen($b); };  usort($words, $compareLength); print(implode("\n", $words)."\n");} if(isset($argv[1])) { $firstArg = $argv[1];} else { exit("One parameter needed");} $dictionary = explode("\n", file_get_contents("ODS6.txt")); $results = search(strtoupper($firstArg), $dictionary); prettyPrint($results);
Output for 5.4.0 - 5.4.32, 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.3 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
<?phpfunction match($desk, $word) { if($desk == "") return false; if($word == "") return true;  $w = $word[0]; $ws = substr($word, 1);  $pos = strpos($desk, $w); if($pos !== false) { return match(substr($desk, 0, $pos).substr($desk, $pos + 1), $ws); }  $pos = strpos($desk, '*'); if($pos !== false) { return match(substr($desk, 0, $pos).substr($desk, $pos + 1), $ws); }  return false;} function search($tokens, $dictionary) { $filter = function($word) use($tokens) { return match($tokens, $word); };  return array_filter($dictionary, $filter);} function prettyPrint($words) { $compareLength = function($a, $b) { return strlen($a) - strlen($b); };  usort($words, $compareLength); print(implode("\n", $words)."\n");} if(isset($argv[1])) { $firstArg = $argv[1];} else { exit("One parameter needed");} $dictionary = explode("\n", file_get_contents("ODS6.txt")); $results = search(strtoupper($firstArg), $dictionary); prettyPrint($results);
Output for 8.0.13
Parse error: syntax error, unexpected token "match" in /in/DpIFn on line 1
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33
Parse error: syntax error, unexpected 'match' (T_STRING) in /in/DpIFn on line 1
Process exited with code 255.

preferences:
146.97 ms | 402 KiB | 172 Q