Creates a Closure that sums the result of applying a callback to each element of an array or iterable — like mapping-then-summing in a single pass.
/**
* @param callable(mixed):(int|float) $function Applied to each value before summing.
* @return Closure(iterable<int|string, mixed>):(int|float)
*/
Arrays\sumWhere(callable $function): ClosureWhen Arrays\sumWhere() is called, it returns the following Closure which can be used like a regular function.
/**
* @param iterable<int|string, mixed> $source
* @return int|float
*/
$function (iterable $source)This can be used to create a simple closure which can be used as a regular function.
$totalAge = Arrays\sumWhere(fn($p) => $p['age']);
echo $totalAge([['age' => 20], ['age' => 30], ['age' => 25]]); // 75This can be called inline using currying.
echo Arrays\sumWhere(fn($n) => $n * 2)([1, 2, 3]); // 12