What are common syntax errors to watch out for when working with PHP, especially in dynamic menu creation?

One common syntax error to watch out for when working with PHP, especially in dynamic menu creation, is improperly closing or nesting PHP tags within HTML code. This can lead to unexpected behavior or errors in the output. To avoid this, make sure to properly open and close PHP tags when switching between PHP and HTML code.

<?php
// Incorrect way of nesting PHP tags within HTML code
echo "<ul>";
foreach ($menuItems as $item) {
    ?>
    <li><a href="<?php echo $item['url']; ?>"><?php echo $item['title']; ?></a></li>
    <?php
}
echo "</ul>";
?>

```

```php
<?php
// Correct way of nesting PHP tags within HTML code
echo "<ul>";
foreach ($menuItems as $item) {
    echo "<li><a href=" . $item['url'] . ">" . $item['title'] . "</a></li>";
}
echo "</ul>";
?>