Skip to content

Today's puzzle · #17 · PHP

Post- and pre-increment together

Sunday, 29 November 2026 · One try

What does this code print?

$i = 5;

echo $i++ + ++$i;

Correct! Not this time. The answer: 12

$i++ gives 5 and then makes $i 6. ++$i makes it 7 and gives 7. 5 + 7 = 12. Code like this is legal but hard to read: avoid it.


                        

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Check your inbox

We sent you a confirmation link. Click it to start receiving new articles.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.