+ 1

PHP - Pre and Post Increments and Decrements Confusion

Hey everyone! I am a teen and I am learning PHP, and I cannot understand what Pre and Post Increments and Decrements are and what their usages are. Things I want to know: What are Increments and Decrements? What are they used for? Thanks!

1st Nov 2019, 9:40 PM
Brock Miller
Brock Miller - avatar
1 Respuesta
+ 2
Adding 1 to a variable can be done with the increment operator (++). Similarly, the decrement operator (--) is used to subtract 1 from a variable. The increment and decrement operators can be used either prefix (before the variable name) or postfix (after the variable name). Which way you use the operator can be important in an assignment statement The prefix form increments/decrements the variable and then uses it in the assignment statement. The postfix form uses the value of the variable first, before incrementing/decrementing it.
6th Nov 2019, 2:38 AM
SUPERFLY🦅
SUPERFLY🦅 - avatar