## 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.

# \$a = 5; var_dump(\$a++); After running the console is 5?

Can someone explain the result above? Thanks.

From what I understand, When you run (\$a++) it returns \$a first and if you were to then var_dump(\$a) afterwards, it would now be 6.

So: <?php \$a = 5; var_dump(\$a++); var_dump(\$a); ?>

will return: int(5) int(6)

Let's look at sequentially (the way the computer sees it) :

• first : \$a = 5;
You assign the value 5 to the variable \$a.
• then : var_dump(\$a++); the var_dump() function displays the values of the arguments you pass it to. In our case, the argument is \$a++. The expression \$a++ does two things, in this order (the order is important) :
• it returns the variable \$a
• then it increments the value of \$a by one. So, since \$a = 5, \$a++ returns 5 and then var_dump(\$a++) returns 5. After that, the value of \$a is incremented. You could easily check that if you wrote : var_dump(\$a++); var_dump(\$a); You'd see it doesn't show the same value the second time, because \$a has been incremented after the first var_dump function was called but before the second one was called.

cheers,

Raphaël

Hi, a++ returns the value of a, and then adds one to the value of a. ++a adds one to the value of a, and then returns the value of a.

cheers,

raphaël

\$a = 5; var_dump(\$a++);

=

\$a = 5; Display the value of \$a and afterwards add 1 (new value not displayed).

with var_dump(\$a++) you first dump the \$a variable and after showing that variable it adds 1 to \$a. with var_dump(++\$a) it will first add 1 to \$a and show it.