3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class ArrayUtils { public static function containsSum($data, $sum) { $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 igEji
Output for 5.6.38 - 7.3.0rc3
bool(true) bool(false)