3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class ArrayUtils { public static function containsSum(array $data, int $sum): bool { $visited = []; foreach ($data as $v) { if (isset($visited[$sum - $v])) { return true; } $visited[$v] = true; } return false; } } $data = range(0, 49999); shuffle($data); var_dump(ArrayUtils::containsSum($data, 1220)); var_dump(ArrayUtils::containsSum($data, -7));
based on MTZNg
Output for 7.0.28 - 7.3.0rc3
bool(true) bool(false)
Output for 5.6.38
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/igEji on line 6
Process exited with code 255.