What are some common pitfalls when using echo to display variables in PHP?

One common pitfall when using echo to display variables in PHP is forgetting to properly concatenate variables with strings. This can result in syntax errors or unexpected output. To solve this issue, always use the concatenation operator (.) to combine strings and variables when using echo.

// Incorrect way of displaying a variable using echo
$variable = "Hello";
echo "The variable is: $variable"; // Incorrect - missing concatenation operator

// Correct way of displaying a variable using echo
$variable = "Hello";
echo "The variable is: " . $variable; // Correct - using concatenation operator