+ 3

I can not understand this ?

$a=2; $b=$a++ Echo $b; The answer is 2 How its does please describe

11th Mar 2019, 12:13 PM
Madhawa Gamage
Madhawa Gamage - avatar
6 Respuestas
+ 11
Its because your assigning the value of $a before its incremented by 1 try assigning ++$a if your expecting 3. $a++ means use the value of $a and then incremenet by one ++$a means incremnet $a by 1 and use it
11th Mar 2019, 12:22 PM
D_Stark
D_Stark - avatar
+ 9
increment: ++, and decrement: --, operators. • These operators can be placed before or after the variable expression they modify. • If they are placed before (a prefix operator), they modify the variable expression before its value is used. • If they are placed after (a postfix operator), they modify the variable expression after its value is used. • The prefix and postfix increment both increase the value of a number by 1. • The only difference between the two is their return value. The former increments (++) first, then returns the value of x, thus ++x. The latter returns the value of x first, then increments (++), thus x++.
11th Mar 2019, 1:19 PM
Danijel Ivanović
Danijel Ivanović - avatar
11th Mar 2019, 12:15 PM
Hubert Dudek
Hubert Dudek - avatar
+ 4
I've suffered a same type of confusion but in other language. Hope it will help you and please use the search bar before posting any questions. Happy coding.... https://www.sololearn.com/discuss/1714986/?ref=app
11th Mar 2019, 6:04 PM
Ayush Sinha
Ayush Sinha - avatar
+ 1
Thank you all guys i got answer
12th Mar 2019, 11:38 AM
Madhawa Gamage
Madhawa Gamage - avatar