Re: RES: [PHP] inexplicable behaviour SOLVED

```Richard Quadling wrote:
> 2009/4/27 9el <le...@phpxperts.net>:
>
>>> Thanks for the clarification, Mike. In my ignorance, I was under the
>>> impression that the right side of the equation was only for the use of
>>> the left part. How stupid of me. So what I should have been doing was
>>> \$Count1 = \$Count + 1; right?
>>>
>>>
>
> \$Count1 = \$Count++;
>
> is not the same as
>
> \$Count1 = \$Count + 1;
>
>
> <?php
> \$Count1 = 100;
> \$Count1 = \$Count1++;
> echo "For \\$Count1 = \\$Count1++; the value in \\$Count1 is \$Count1", PHP_EOL;
> \$Count1 = \$Count1 + 1;
> echo "For \\$Count1 = \\$Count1 + 1; the value in \\$Count1 is \$Count1", PHP_EOL;
>
>
> outputs ...
>
> For \$Count1 = \$Count1++; the value in \$Count1 is 100
> For \$Count1 = \$Count1 + 1; the value in \$Count1 is 101
>
>
> This shows that post-inc during an assignment does not affect the
> value assigned.
>
>
> Something that I thought would happen was if I ...
>
> <?php
> \$Count1 = 100;
> echo \$Count1 = \$Count1++, PHP_EOL;
> echo \$Count1, PHP_EOL;
>
> I thought I'd get ...
>
> 101
> 100
>
> but I get
>
> 100
> 100
>
> I thought the ++ would happen AFTER the assignment and the ++ to the
> value of the assignment. But this is not the case.
>
>
>> \$Count = \$Count + 1; is exactly(?) same as \$Count++; Â or ++\$Count
>> But not exactly same. Â PostFix notation adds the value after assigning.
>> PreFix notation adds the value right away.
>>
>>
>>
>>> Anyway, I don't need that statement anymore as I found the error of my
>>> ways and have corrected it. And behold, the light came forth and it
>>> worked. :-)
>>>
>>>
>> Regards
>>
>> Lenin
>>
>> www.lenin9l.wordpress.com
>>
Thanks. That is really a nice eye-opener.
Phil```
```
--
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-------------------------------------------------------------
Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php

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

```