How can the active tab in PHP be passed as a variable?

To pass the active tab in PHP as a variable, you can use a combination of HTML and PHP to dynamically set the active tab based on the current page. You can achieve this by using a conditional statement to check if the current page matches the tab, and then adding an 'active' class to the tab accordingly.

<?php
$current_page = basename($_SERVER['PHP_SELF']);
?>

<ul class="nav">
    <li class="<?php echo ($current_page == 'home.php') ? 'active' : ''; ?>"><a href="home.php">Home</a></li>
    <li class="<?php echo ($current_page == 'about.php') ? 'active' : ''; ?>"><a href="about.php">About</a></li>
    <li class="<?php echo ($current_page == 'contact.php') ? 'active' : ''; ?>"><a href="contact.php">Contact</a></li>
</ul>