Are there any best practices for organizing PHP code within HTML elements like tables for menus?

When organizing PHP code within HTML elements like tables for menus, it is best practice to separate the PHP logic from the HTML markup. This can be achieved by using PHP to generate the necessary HTML elements dynamically. By doing so, the code becomes more maintainable and easier to read.

<?php
$menuItems = array("Home", "About", "Services", "Contact");

echo "<ul>";
foreach ($menuItems as $item) {
    echo "<li><a href='#'>$item</a></li>";
}
echo "</ul>";
?>