How can variables be properly concatenated in PHP to avoid syntax errors or unexpected behavior?

When concatenating variables in PHP, it's important to properly use the concatenation operator (.) to avoid syntax errors or unexpected behavior. Ensure that there are no spaces between the variable name and the concatenation operator. Additionally, wrap variables in curly braces ({}) within double quotes to clearly define the variable name within the string.

// Correct way to concatenate variables in PHP
$var1 = "Hello";
$var2 = "World";
echo "{$var1} {$var2}";