Parafost Posted June 3, 2011 Share Posted June 3, 2011 Hey all, I have been trying to get into PHP for a while now and I have a question that if someone could explain to me I would really appreciate it. The code is as follows; $a = 57; $b = "$a + 3"; echo $b; $c = $a + 3; $d = 54; echo $c; Now I am aware that the answer to the first question would be 60. But, I am curious, without the " around $a + 3; will there be any change to the answer or will the answer still show as 60? if the use / no use of the " " could be explained I would really appreciate it. Thanks a lot Para Quote Link to comment Share on other sites More sharing options...
revraz Posted June 3, 2011 Share Posted June 3, 2011 Did you remove the quotes to see what the answer would be? Did you really echo $b? Quote Link to comment Share on other sites More sharing options...
WebStyles Posted June 3, 2011 Share Posted June 3, 2011 values inside quotes ("...") are treated as strings. $a = 57; is a number. $a = "57"; is a string. you can use functions like is_int, intval, etc... to figure out if variables are numbers or strings. what's also happening with your code is that you're echoing $a and $c right after each other with no space or line break. try this to separate them on different lines: echo '<br>A = '.$a; echo '<br>C = '.$c; hope this helps Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.