I'm new here. I'm not super new to PHP but my questions are very basic as I have never had the time to get to deep into php.
OK, I have a main page called index.php
I also have an "include file" (not sure if thats how you refer to it in php) called IncludeFile.php
The first line of index.php is:
<?php
include("IncludeFile.php");
IncludeFile.php starts of with some variable definitions:
$Var1 = "xxx";
$Var2 = "yyy";
So my problem is, when I call a function in IncludeFile.php from index.php, the variable are undefined in the function. Even though they are defined at the top of the include file and are available perfectly in index.php.
i.e. IncludeFile.php has the following
$Var1 = "xxx";
$Var2 = "yyy";
function FormatVar1(){
return "This is formatted: " . $Var1;
}
What I want to get from the above function (when calling it from index.php) is:
"This is formatted: xxx"
but what i get instead is:
"This is formatted:"
Why is the scope of the variable defined in the include file limited only to the includer (index.php) and not available to functions inside the include file itself?
Also, I know there are much better ways to do what this example function does. It was just an easy way for me to describe my problem.
Thanks in advance to any replies.