foreach($group as $key=>$value) { echo $key. " = " .$value. "<br>"; }
For example:
doc1 = 8
doc2 = 7
doc3 = 1
I want to count $value, so the result is 8+7+1 = 16. What should i do?
Thanks.
$sum = 0; foreach($group as $key => $value) { $sum += $value; } echo $sum; But if you want to go with direct sum of array than look on below for your solution : $total = array_sum($group);
array_sum() function in PHP The array_sum() function returns the sum of the values in an array. The returned value can be integer or float. It returns 0 if the array is empty.
break ends execution of the current for , foreach , while , do-while or switch structure.
$sum = 0; foreach($group as $key=>$value) { $sum+= $value; } echo $sum;
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