What are some best practices for creating a simple page navigation system using PHP?

When creating a simple page navigation system using PHP, it is important to keep the code clean and organized. One best practice is to separate the navigation logic from the rest of the page content. This can be done by creating a separate PHP file for the navigation menu and including it in each page where navigation is needed. Another best practice is to use a loop to generate the navigation links dynamically based on the number of pages.

<?php
// Define total number of pages
$totalPages = 10;

// Get current page number from URL parameter
$page = isset($_GET['page']) ? $_GET['page'] : 1;

// Display navigation links
echo '<div>';
for ($i = 1; $i <= $totalPages; $i++) {
    if ($i == $page) {
        echo "<span>$i</span>";
    } else {
        echo "<a href='?page=$i'>$i</a>";
    }
}
echo '</div>';
?>