3v4l.org

run code in 300+ PHP versions simultaneously
<?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));
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
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.

preferences:
84.59 ms | 401 KiB | 73 Q