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
Share
When you write this :
PHP will search for a
$langvariable that is local to the function :$langvariable set, inside the function,$lang['fname']will benull— i.e. it will not display anything whenechoed.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 :For more informations, you should read the Variable scope section of the PHP manual.