Re: FW: [PHP-WIN] Math Operator Problem?

From: Date: Mon, 09 Feb 2009 16:58:58 +0000
Subject: Re: FW: [PHP-WIN] Math Operator Problem?
References: 1 2 3  Groups: php.windows 
Request: Send a blank email to php-windows+get-29165@lists.php.net to get a copy of this message
On Mon, 2009-02-09 at 11:26 -0500, Alice Wei wrote: <snip> > > > while (!feof($fh2)) { > > > > > > $total_time=0; > > > $lines= fgets($fh2); > > > $count= strlen($lines); > > > if ($count == 0) { > > > //There are no lines > > > } > > > else { > > > > > > $total_time += $lines; > > > > > > } > > > } <snip> > 3 > 4 > 2 > > Note that there is an extra line break after the last line, but I am not sure if that was what > caused the problem. My code above intentionally made the calculation leave out the last line. Or, is > it not what it was doing? > Alice, I reread your post and think I understand now what you are trying to do. Every time the while() loop runs (for each line in $fh2) the $total_time variable gets set to '0'. When the if/else loop runs 0 gets added to $lines and the result will always be the value of $lines. If you want the $total_time to increment with each line in the $fh2 file then you need to declare it outside the while() loop instead of inside the loop. Cheers, James

« previous php.windows (#29165) next »