RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo

From: Date: Wed, 07 Oct 2009 12:59:23 +0000
Subject: RE: [PHP] Whacky increment/assignment logic with $foo++ vs ++$foo
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.general 
Request: Send a blank email to php-general+get-298723@lists.php.net to get a copy of this message
On Wed, 2009-10-07 at 08:54 -0400, tedd wrote: > At 6:15 PM -0700 10/6/09, Daevid Vincent wrote: > >Except that: > > > >$a = 123; > >$b = $a++; > >echo $b; //gives 123, not 124 > > > >as you logically expect it to and common sense would dictate, regardless of > >what K&R or anyone else says. > > That's not the way I look at it. > > $b = $a++; > > means to me "take the value of $a and assign to $b and then increment $a." > > Whereas: > > $b = ++$a; > > means to me "increment $a and take the value of $a and assign to $b." > > Cheers, > > tedd > > -- > ----- > http://sperling.com > http://ancientstones.com > http://earthstones.com > Which is exactly the reason for the two operators in C. Thanks, Ash http://www.ashleysheridan.co.uk

« previous php.general (#298723) next »