Assigning a variable to a file

Hello everyone,

I am trying to achieve something very simple.

I have a footer.php file which I would like to include() into my index.php


/*footer.php*/

    <ul>
        <li><a href="#">About Us</a></li>
        <li><a href="#">Financing</a></li>
        <li><a href="#">Contact Us</a></li>
    </ul>

Currently, I am including the footer into my index.php using the following method:


<?php
if(file_exists("includes/footer.php")){
include ("includes/footer.php");
}
?>

As you can see, I am repeating “includes/php” twice. I figured that it is easier to assign this file as a variable, so I may use the following code instead:


<?php
if(file_exists($footer)){
include ($footer);
}
?>

But I have no idea how to assign a file as a variable. Thanks for any tips.

In this case, $footer = ‘includes/footer.php’; is all you need

Thank you, Tim.