Is there a php function that returns the sum of a row of an associative array?
If not should I just use a counter and a foreach loop?
Appreciate it!
To get the sum based on a certain column key, use this:
array_sum(array_column($assoc_array, 'key_name'));
array_sum will work for you.
$arr = array(
'key1' => 54.3,
65 => 10
);
$sum = array_sum($arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With