Re: RES: inexplicable behaviour SOLVED

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

 



Richard Quadling wrote:
> 2009/4/27 9el <lenin@xxxxxxxxxxxxx>:
>   
>>> 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;
> echo "Start with $Count1", PHP_EOL;
> $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 ...
>
> Start with 100
> 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.
>> But optimized programming argues about how machine is coded nowadays.
>>
>>
>>     
>>> 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.twitter.com/nine_L
>> 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 --- pj@xxxxxxxxxxxxx
   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


[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