How can syntax errors, such as unexpected variables, be avoided in PHP code?

To avoid syntax errors like unexpected variables in PHP code, it is essential to carefully review the code for typos, missing semicolons, and incorrect variable names. Using an integrated development environment (IDE) with syntax highlighting and error checking can also help catch these issues before running the code.

// Incorrect code with unexpected variable
$name = "John";
echo "Hello, $name";
```

```php
// Corrected code with proper variable usage
$name = "John";
echo "Hello, " . $name;