0
Can Anyone clear me please?
<?php $str="10"; $str="20"; $sum=$str+$str; echo $sum; //output is 40 why? ?>
7 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.
+ 1
Thank you@Phi Long Le @Robin
0
not understand.
0
it means we can't add strings but string converted into integer.and first value(10) Replace into second value(20). is it?