Re: loop Q
| From: | William Stokes | Date: | Fri, 24 Feb 2006 12:11:42 +0000 |
| Subject: | Re: loop Q | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-231014@lists.php.net to get a copy of this message | ||
Cheers!
"Jochem Maas" <jochem@iamjochem.com> kirjoitti
viestissä:43FEF19F.5020509@iamjochem.com...
> 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
>>