Jump to content

String help


Parafost

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/238280-string-help/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/238280-string-help/#findComment-1224581
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.