can we add one integer variable and one string variable???? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

can we add one integer variable and one string variable????

3rd Jul 2016, 6:37 AM
Manvitha Gottipati
Manvitha Gottipati - avatar
4 Answers
+ 5
Yes you can add integer to string. php automatically casts the string to integer and adds it to the integer. ex:"12"+10 will result in 22 as string 12 is cast into integer 12. "11abc"+ 12 will result in 23 as 11 abc is cast to integer 11.
3rd Jul 2016, 6:49 AM
Midhun Mathew
+ 2
For example $str = "I'm " ; $int = 20; $âge = $str + $int; echo ($age); => The output is "I'm 20"
11th Jul 2016, 8:53 PM
MARINA
MARINA - avatar
0
thanks for the ans... can you give me a real time example where we need addition of two different data
3rd Jul 2016, 7:00 AM
Manvitha Gottipati
Manvitha Gottipati - avatar
0
yes u can add in PHP because it is loosEly typed language.
4th Jul 2016, 2:17 PM
Ashutosh Pandey
Ashutosh Pandey - avatar