tburgess Posted April 24, 2013 Share Posted April 24, 2013 Hi, I hope the fact that I have a question on Ch1 doesn't mean I am not up to this but we will see. Basically it's to do with concatenation. On page 25, section 5, 3rd line of the echo, a cost of <b>$' . $price . '</b> I don't understand the ' . $price . ' basically. Why the space either side of $price and each side of the dots? Any help understanding this is greatly appreciated. Thanks, Tom Link to comment Share on other sites More sharing options...
Larry Posted April 24, 2013 Share Posted April 24, 2013 Hello Tom, The space actually just makes it easier to read. It has no functional purpose. a cost of $'.$price.' would work just the same. 1 Link to comment Share on other sites More sharing options...
tburgess Posted April 25, 2013 Author Share Posted April 25, 2013 Hey, thanks for the reply! So why not just a cost of <b>\$$price. ? Link to comment Share on other sites More sharing options...
margaux Posted April 25, 2013 Share Posted April 25, 2013 That would work if you enclosed it within double quotes but not single quotes. $price='12.34'; echo 'a cost of <b>\$$price </b>'; // a cost of \$$price echo "a cost of <b>\$$price</b>"; // a cost of $12.34 You might want to try different combinations of single and double quotes to confirm your understanding. 1 Link to comment Share on other sites More sharing options...
tburgess Posted April 26, 2013 Author Share Posted April 26, 2013 Excellent thanks Got all that now! Last question on Ch1, page 25 section 5, why use the concatenation operator within the echo? Is that because it is within single quotes and the variables would be taken literally if concat wasn't used? Thanks, Tom Link to comment Share on other sites More sharing options...
HartleySan Posted April 26, 2013 Share Posted April 26, 2013 Yes, all variables are interpreted literally when in single quotes. Again, as margaux suggested, making a sample script and testing these things out is the easiest way to learn. Link to comment Share on other sites More sharing options...
Recommended Posts