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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.