How can one dynamically highlight a specific page number in a navigation menu using PHP?

To dynamically highlight a specific page number in a navigation menu using PHP, you can compare the current page number with the page number in the navigation menu and add a CSS class to the corresponding link to apply the highlighting effect. This can be achieved by checking the current page number against a variable or using a conditional statement to determine which link should be highlighted.

<?php
$current_page = 2; // Assuming the current page number is 2

for ($i = 1; $i <= 5; $i++) {
    if ($i == $current_page) {
        echo '<a href="#" class="highlighted">Page ' . $i . '</a>';
    } else {
        echo '<a href="#">Page ' . $i . '</a>';
    }
}
?>