Re: loop Q

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



William Stokes wrote:
What does this do in a for loop?

$counter+=1


it's shorthand for $counter = $counter + 1;
which in this case (because 1 is being added)
can also be written as:

$counter++;

or

++$counter;


those last 2 alternatives give the same result
but they are _not_ exactly equivalent - it has to do
with when the incrementation is done when such expression
appears inside a more complex expression e.g.

$counter = 1;
$x = ++$counter;
$counter = 1;
$y = $counter++;
echo $x,",",$y,"\n"; // outputs: 2,1




Thanks

-Will


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux