How can concatenating strings and variables in PHP be done correctly to avoid syntax errors?

When concatenating strings and variables in PHP, it's important to properly use the concatenation operator (.) to avoid syntax errors. Make sure to enclose variables within curly braces {} to clearly separate them from the surrounding text. This helps PHP interpret the variable correctly within the string.

// Correct way to concatenate strings and variables in PHP
$name = "John";
$age = 30;

echo "My name is {$name} and I am {$age} years old.";