Jump to content

Recommended Posts

I don't know how to search for this, so forgive me if it's been covered...

 

I often see an example like this:

$a = $b . " " . $c;  // concatenate strings with space

 

I'm wondering if there is something wrong with this method:

$a = "$b $c";

 

I can see that maybe the 1st method is more clear as to intention, but I'm not sure if it's really worth the extra trouble.  What do you guys think?

 

Thanks,

Marty Fried

The second method generally produces fewer syntax errors because there are fewer transitions between different syntax elements to keep track of. It is easier to see the syntax of what you are trying to produce, a quoted string, when you really only have one quoted string to look at.

The second method generally produces fewer syntax errors because there are fewer transitions between different syntax elements to keep track of. It is easier to see the syntax of what you are trying to produce, a quoted string, when you really only have one quoted string to look at.

Thanks, that's kinda what I thought, too.  But most of the tutorials I read seem to use the first method.  I'm an old C/C++ programmer, but new to PHP, and after learning about the effects of double quotes, thought the second method should work, and it did.  Makes things a lot easier.

 

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.