I haven't found a very good answer to my problem so I'm starting a new topic. I have the file english.php which has variables like $lang['fname'] = "First name";. Also I have header.php which includes english.php : include('english.php');. Now, header.php is included in another php page, let say addInfo.php. If I write in addInfo.php : echo $lang['fname']; it shows me "First name", but if i write a function in addInfo.php, as example function added () { echo $lang['fname'];} and then added(); (i tried also echo added()) it doesn't want to display the value("First name"). Does somebody know a solution for this sample(i think) problem. I'm ready to try all answers. Regards, StefanZ
When you write this :
function added () {
echo $lang['fname'];
}
PHP will search for a $lang
variable that is local to the function :
$lang
variable set, inside the function, $lang['fname']
will be null
-- i.e. it will not display anything when echo
ed.
To indicate to PHP that it should use the global variable from outside the function, you need to declare the variable as global
, inside the function :
function added () {
global $lang;
echo $lang['fname'];
}
For more informations, you should read the Variable scope section of the PHP manual.
you have to state global $lang in your function
ex.
function added(){
global $lang;
echo $lang["fname"];
}