CKTIS / PHP
array_sum()
Add numeric array values to calculate a total.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_sum(array $array): int|floatAdd numeric array values to calculate a total. An empty array contributes the additive identity zero, while a fractional value can make the result a float. In PHP 8.4 values that cannot be converted to a number can produce warnings, so validate incoming amounts before summing them.
Signature
array_sum(array $array): int|float
Example output
[5.5,0]
Examples
<?php
echo json_encode([array_sum([2,'3',0.5]), array_sum([])]);
Result
[5.5,0]