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? Link to comment https://forums.phpfreaks.com/topic/121206-what-is-the-deifference-between-post-increment-and-pre-increment/ 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. Link to comment https://forums.phpfreaks.com/topic/121206-what-is-the-deifference-between-post-increment-and-pre-increment/#findComment-624805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.