PHP issue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

PHP issue

Please, explain the difference of the results of the code. The essence of the examples is the same, the recording is different and for some reason different results. https://code.sololearn.com/wdW992lqkxG9/?ref=app

3rd Jan 2021, 6:34 PM
Evgeniy Reut
2 Answers
+ 1
You missed the parenthesis in the part with b. In the one with a, you are performing the arithmetic on the right side of the += operator and THEN add to value of a. In the second one to have same effect, you need to perform the required arithmetic first (by using parenthesis - parenthesis are high priority), and then add to value of b. I added the editted code. Hope it helps. https://code.sololearn.com/w1agm7F2sV3Z/?ref=app
4th Jan 2021, 2:23 PM
Rukshan J. Senanayaka
Rukshan J. Senanayaka - avatar
0
Thank you for the answer But can you explain, why result in my 2nd example is 6
6th Jan 2021, 9:35 PM
Evgeniy Reut