What are some best practices for handling context switches between PHP and HTML code?

When handling context switches between PHP and HTML code, it is best practice to separate the PHP logic from the HTML markup to improve code readability and maintainability. One way to achieve this is by using PHP's alternative syntax for control structures, such as `if`, `foreach`, and `while`, to embed PHP code within HTML templates.

<?php
// PHP logic
$items = ['Item 1', 'Item 2', 'Item 3'];

// HTML markup
?>
<ul>
<?php foreach ($items as $item): ?>
    <li><?php echo $item; ?></li>
<?php endforeach; ?>
</ul>