You can use the PHP array_sum() function to calculate the sum of all numeric values in an array. As shown in the following example:
How to calculate sum of an array in PHP
<?php
$arr1 = array(1, 2, 3);
$arr2 = array("a" => 1, "b" => 2, "c" => 3);
echo array_sum($arr1). '<br />';
echo array_sum($arr2);
?>
Output:
6
6