run code in 200+ php & hhvm versions
Bugs & Features
<?php final class ArrayUtils { private static $visited = []; private static $sum = 0; public static function containsSum(array $data, int $sum): bool { self::$visited = []; self::$sum = $sum; return array_reduce($data, 'ArrayUtils::reduce', false); } private static function reduce(bool $carry, int $item): bool { $carry |= isset(self::$visited[self::$sum - $item]); self::$visited[$item] = true; return (bool) $carry; } } $data = range(0, 49999); shuffle($data); var_dump(ArrayUtils::containsSum($data, 1220)); var_dump(ArrayUtils::containsSum($data, -7));
based on OQOip

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for Typed properties v2
bool(true) bool(false)

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page