lucerias Posted November 10, 2006 Share Posted November 10, 2006 May i know when to use global, when to use var? If let say i require x.php file into y.php file by using require syntax, and want to use the variable in the x.php file, do i have to declare again in y.php file or i can directly make use of it and then value can be passed from x.php to y.php? Thank you Quote Link to comment Share on other sites More sharing options...
btherl Posted November 10, 2006 Share Posted November 10, 2006 You don't need global when including files.You need global when you want to access a variable from inside a function. Eg[code=php:0]$var = 5;function foo() { global $var; print "var = $var\n";}[/code] Quote Link to comment Share on other sites More sharing options...
lucerias Posted November 10, 2006 Author Share Posted November 10, 2006 If i use require or include method to include x.php into y.php, and then i include y.php into z.php, can i make use of the parameter stored in x.php with z.php? Thank you. Quote Link to comment Share on other sites More sharing options...
btherl Posted November 10, 2006 Share Posted November 10, 2006 Yes you can. Try it and see for yourself :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.