Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

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.

  • Upvote 1
Link to comment
Share on other sites

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

 Share

×
×
  • Create New...