2020-11-01 03:50:25 -05:00
|
|
|
---
|
|
|
|
|
title: stdlib / array_sum
|
|
|
|
|
---
|
2023-11-25 09:50:24 -08:00
|
|
|
# array_sum
|
2020-11-01 03:50:25 -05:00
|
|
|
|
|
|
|
|
### NAME
|
|
|
|
|
|
|
|
|
|
array_sum() - return the sum of all of the numeric elements of the passed array
|
|
|
|
|
|
|
|
|
|
### SYNOPSIS
|
|
|
|
|
|
|
|
|
|
int|float sum( mixed* );
|
|
|
|
|
|
|
|
|
|
### DESCRIPTION
|
|
|
|
|
|
|
|
|
|
This function will aggregate the values of all elements of the passed
|
|
|
|
|
array into a single return value. The array may be any combination of
|
|
|
|
|
int or float and the appropriate type will be returned based on the
|
|
|
|
|
final total.
|
|
|
|
|
|
|
|
|
|
### EXAMPLE
|
|
|
|
|
|
2020-12-10 16:42:33 -08:00
|
|
|
```c
|
2020-11-01 03:50:25 -05:00
|
|
|
array_sum( ({ 1, 2, 3, 4, 5, 6 }) ); // Result: 21
|
|
|
|
|
array_sum( ({ 1, 2, 3.5, 4, 5, 6 }) ); // Result: 21.500000
|
2020-12-10 16:42:33 -08:00
|
|
|
```
|
2020-11-01 03:50:25 -05:00
|
|
|
|
|
|
|
|
### SEE ALSO
|
|
|
|
|
|
|
|
|
|
sum
|