phpcharan Posted August 25, 2008 Share Posted August 25, 2008 What is the deifference between Post Increment and Pre Increment? and how they are useful? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 25, 2008 Share Posted August 25, 2008 Try running the following two code snippets: $foo = 6; $bar = 5; if($foo == $bar++){ echo 'True. Foo:'.$foo.' Bar:'.$bar; }else{ echo 'False. Foo:'.$foo.' Bar:'.$bar; } $foo = 6; $bar = 5; if($foo == ++$bar){ echo 'True. Foo:'.$foo.' Bar:'.$bar; }else{ echo 'False. Foo:'.$foo.' Bar:'.$bar; } As you will see, in both cases, after the if statement, both $foo and $bar are 6. However, only the if statement in the second code snippet is true. That is because $bar is incremented prior to being tested for equality. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.