What are some best practices for structuring PHP code to handle dynamic content generation for headers and footers?

When dealing with dynamic content generation for headers and footers in PHP, it is best practice to separate the logic from the presentation by using include or require statements to pull in the header and footer files. This allows for easier maintenance and updates to the codebase.

<?php
// header.php
echo "<header>";
// dynamic content generation for header
echo "</header>";

// index.php
include 'header.php';
// main content of the page
include 'footer.php';
?>