linfidel Posted October 23, 2009 Share Posted October 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/178779-solved-quick-basic-question-hopefully-not-dumb/ Share on other sites More sharing options...
Alex Posted October 23, 2009 Share Posted October 23, 2009 There's nothing wrong with your method, they both accomplish the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/178779-solved-quick-basic-question-hopefully-not-dumb/#findComment-943087 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2009 Share Posted October 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178779-solved-quick-basic-question-hopefully-not-dumb/#findComment-943122 Share on other sites More sharing options...
linfidel Posted October 23, 2009 Author Share Posted October 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/178779-solved-quick-basic-question-hopefully-not-dumb/#findComment-943150 Share on other sites More sharing options...
PFMaBiSmAd Posted October 24, 2009 Share Posted October 24, 2009 Or you can use methods that are similar to how you would do it in C/C++ - http://www.phpfreaks.com/forums/index.php/topic,273584.msg1292539.html#msg1292539 Quote Link to comment https://forums.phpfreaks.com/topic/178779-solved-quick-basic-question-hopefully-not-dumb/#findComment-943500 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.