Jump to content

[SOLVED] quick basic question, hopefully not dumb


linfidel

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.

 

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.