<?php
//variables.php
$name = 'Loretta';
$age = '27';
?>
Now we will include this file into our second file called report.php
<?php
//report.php
include 'variables.php';
// or you can use the full path; include 'http://www.yoursite.com/folder/folder2/variables.php';
print $name . " is my name and I am " . $age . " years old.";
?>
As you can see, the print command easily uses these variables. You can also call the include within a function but we must declare the variables to be GLOBAL if we want to use them outside the function:
<?php
function printname ()
{
global $name;
include 'variables.php';
print $name . " is my name and I am " . $age . " years old.";
}
printname ();
print "<br>";
//The line below will work because $name is GLOBAL
print "I like my name, " . $name;
print "<br>";
//The next line will NOT work because $age is NOT defined as global
print "I like being " . $age . " years old.";
?>

