Re: RES: [PHP] inexplicable behaviour SOLVED

From: Date: Tue, 28 Apr 2009 07:51:53 +0000
Subject: Re: RES: [PHP] inexplicable behaviour SOLVED
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-292060@lists.php.net to get a copy of this message
2009/4/27 9el <lenin@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; 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 > -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"

« previous php.general (#292060) next »