I have an HTML form that passes information, specifically a number that I want to add. When I add these values, for some reason a couple of my values are not being added correctly. Here's my original code:
Here is the array being passed from the form:
289.03
439.08
147.35
153.82
163.94
382.76
2359.43
1983.83
And here's the PHP code:
<?php
$netRate = $_POST['netrate'];
$payloads = $_POST['topay'];
$netLoad=0;
for($i=0;$i<=count($payloads);$i++)
{
if(!empty($payloads[$i]))
{
///other code is in here/////
echo '<td width="60" valign="top">'.$netRate[$i].'</td>';
$netLoad = $netLoad + $netRate[$i];
echo "net rate: ". $netRate[$i];
echo "<br>";
echo "net load (sum of all loads): ". $netLoad;
echo "<br>";
}
}
?>
These are the results that I get from the echo statements:
net rate: 289.03
net load (sum of all loads): 289.03
net rate: 439.08
net load (sum of all loads): 728.11
net rate: 147.35
net load (sum of all loads): 875.46
net rate: 153.82
net load (sum of all loads): 1029.28
net rate: 163.94
net load (sum of all loads): 1193.22
net rate: 382.76
net load (sum of all loads): 1575.98
net rate: 2,359.43
net load (sum of all loads): 1577.98
net rate: 1,983.83
net load (sum of all loads): 1578.98
So even though the last two $netRate parts of the array are correct (2359.43 & 1983.83) the $netLoad did not add them correctly. What could be the issue here?
foreachinstead offor, there is a significant difference in performance.