$variable + $variable = error

Im puzzled by the result of adding two wariables together in my script. The script loops throug an array and is supposed to calculate running a total of hours worked:

$counter = 1;
$arrhr = 0;
$hr = 0;
while ( $counter <= 1000 ) {
$counter = $counter + 1;

$array[$counter][2]; //number of hours worked

$arrhr = $array[$counter][2];
echo $arrhr; //output for debugging

$hr = $hr + $arrhr;
echo “$hr + $arrhr =” . $hr;

The scripts loop through the array and output the first echo $arrhr statment correctly. But the next echo statement comes out like this:

0 +
4.5 (this is the correct $arrhr value)

Im sure im missing something obvious :slight_smile:

What this line means in your code?

$array[$counter][2]; //number of hours worked

You’re not assigning anything there…

Sponsor our Newsletter | Privacy Policy | Terms of Service