3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class ArrayUtils { public static function containsSum($data, $sum) { $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, 9999); shuffle($data); var_dump(ArrayUtils::containsSum($data, 1220)); var_dump(ArrayUtils::containsSum($data, -7));
based on ESQpB
Output for 7.1.0 - 7.3.0rc3
bool(true) bool(false)
Output for 5.6.38 - 7.0.28
bool(true)
Process exited with code 137.