What are the best practices for structuring PHP files to create a modular layout with header, footer, and navigation includes?

When creating a modular layout in PHP, it's best practice to separate the header, footer, and navigation into separate files and include them where needed. This makes the code more organized, easier to maintain, and allows for reusability. By using include or require statements, you can easily incorporate these modular components into your main PHP files.

<?php
// header.php
?>
<!DOCTYPE html>
<html>
<head>
    <title>Modular Layout Example</title>
</head>
<body>

<?php
// navigation.php
?>
<nav>
    <a href="#">Home</a>
    <a href="#">About</a>
    <a href="#">Contact</a>
</nav>

<?php
// main content file
include 'header.php';
include 'navigation.php';

// main content goes here

// footer.php
include 'footer.php';
?>
</body>
</html>