Ask Your Question
4

How come the expression $x=5; $x+++$x++; evaluates to 11 in PHP?

asked 2023-04-30 16:16:30 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-04-30 16:24:02 +0000

plato gravatar image

It evaluates to 11 because the expression first increments $x by 1 (x++), then increments it again by 1 ($x++), and then adds the current value of $x to itself (5+6). So the final value of $x is 7 and the expression evaluates to 11.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-04-30 16:16:30 +0000

Seen: 8 times

Last updated: Apr 30 '23