I have a foreach loop that is outputting a bunch of numbers and then I want to take all of those numbers and add them together. However, when I do this, it only adds together whats before the decimal point. I feel like maybe I am missing something with number_format maybe??
Here is the code:
$totalHours = '0';
foreach ($timeEntries as $entry) {
$entryID = $entry->id;
$entryHours = $entry->hours;
$entryDate = $entry->spent_at;
$totalHours += $entryHours;
echo $entryHours."<br />";
}
echo "All added up: $totalHours <br />";
And that is displaying the following:
0.7
0.5
0.53
2.6
0.8
0.2
0.5
2.22
1.28
0.57
0.55
0.35
0.5
0.5
1.2
1.4
1.2
0.5
0.82
1.0
0.17
0.33
2.0
1.0
0.5
1.0
0.17
1.97
All added up: 14
Any ideas?