I have this array and I want to add the values:
$sustainCapital_arr = Array ( [0] => 2,759 [1] => 3,269 [2] => 3,481 [3] => 3,573 [4] => 3,997 [5] => 4,421 [6] => 10,999 )
now, interestingly array_sum is giving me an incorrect number:
$total_Sustaining = array_sum($sustainCapital_arr); output: 28 ???
Output should be 32,499.
Now, I also tried to use a foreach loop and the same happens. What the hell is going on here?
$total_Sustaining = 0;
foreach ($sustainCapital_arr as $key=>$value){
$total_Sustaining += $value;
}
output is again 28!!!
What am I doing wrong here?
>Solution :
$total_Sustaining = 0;
foreach ($sustainCapital_arr as $key=>$value){
$total_Sustaining += filter_var($value, FILTER_SANITIZE_NUMBER_INT);
}