array_sum

Calculate the sum of values in an array

&reftitle.description; ``int``float```array_sum` `array` `array`

`array_sum` returns the sum of values in an array.

&reftitle.parameters;

`array`

- The input array.

&reftitle.returnvalues;

Returns the sum of values as an integer or float; `0` if the `array` is empty.

&reftitle.changelog;

&Version; | &Description;
8.3.0 | Now emits `E_WARNING` when `array` values cannot be converted to &integer; or &float;. Previously &array;s and &object;s where ignored whilst every other value was cast to &integer;. Moreover, objects that define a numeric cast (e.g. `GMP`) are now cast instead of ignored.

&reftitle.examples;

### `array_sum` examples

    <?php
    $a = array(2, 4, 6, 8);
    echo "sum(a) = " . array_sum($a) . "\n";

    $b = array("a" => 1.2, "b" => 2.3, "c" => 3.4);
    echo "sum(b) = " . array_sum($b) . "\n";
    ?>

&example.outputs;

    sum(a) = 20
    sum(b) = 6.9