PHP – concatenate or directly insert variables in string

I am wondering, What is the proper way for inserting PHP variables into a string?

This way:

echo "Welcome ".$name."!"

Or this way:

echo "Welcome $name!"

Both of these methods work in my PHP v5.3.5. The latter is shorter and simpler but I’m not sure if the first is better formatting or accepted as more proper.

14 Answers
14

Leave a Comment