Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNick Evershed
6,429 PointsWhy is this not 6
Im so confused how this does not = 6?
$a = 5; var_dump($a++);
Will display what value?
1 Answer
Steven Parker
231,248 PointsThe "++" operator placed after a variable performs what is known as a "post-increment". This means that the current value of the variable is returned and then an increment is performed on it afterwards.
So the value in the variable does become 6, but it's not seen until the next time the variable is referenced.
If you wanted the increment to be performed first, you could put the operator symbol on the left side of the name instead. That's a "pre-increment".