Can Anyone clear me please? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can Anyone clear me please?

<?php $str="10"; $str="20"; $sum=$str+$str; echo $sum; //output is 40 why? ?>

21st Feb 2017, 1:40 PM
TherBishal
TherBishal - avatar
4 Answers
+ 1
@ therbishal you created the first variable ($str="10"), but by using the same variable name ($str="20") you have effectively changes the value of $str to 20. so by adding str+str, you get 40. change the name of the second variable to str2. this way it will add together str=10 +str2=20. sum = 30. also, by using quotations on the value of the variable makes the numbers a string.
21st Feb 2017, 4:51 PM
Robin
Robin - avatar
+ 1
Thank you@Phi Long Le @Robin
21st Feb 2017, 5:00 PM
TherBishal
TherBishal - avatar
0
not understand.
21st Feb 2017, 2:02 PM
TherBishal
TherBishal - avatar
0
it means we can't add strings but string converted into integer.and first value(10) Replace into second value(20). is it?
21st Feb 2017, 2:09 PM
TherBishal
TherBishal - avatar