3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class ArrayUtils { public static function containsSum(array $data, int $sum): bool { $max = count($data); for ($i = 0; $i < $max; $i += 1) { $v1 = $data[$i]; for ($j = $i + 1; $j < $max; $j += 1) { $v2 = $data[$j]; if ($v1 + $v2 === $sum) { return true; } } } return false; } } $data = range(0, 4999); 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/ESQpB on line 6
Process exited with code 255.