siwelis Posted May 28, 2007 Share Posted May 28, 2007 $var1; function Test(){ echo $var1; } function() ------------------------ Can anyone tell me why the function doesn't recognize predermined vars? Quote Link to comment https://forums.phpfreaks.com/topic/53239-solved-passing-vars-to-funtions/ Share on other sites More sharing options...
chronister Posted May 28, 2007 Share Posted May 28, 2007 global Variables set inside a function are available only to that function. Vars set outside that function are only available to items outside functions. You need to look in the manual regarding the scope of variables. $var1=4; $var2=3; $var3=6; function Test(){ global $var1,$var2,$var3; echo $var1+$var2+$var3; } Test(); This returns 13 If you drop out the global, those variables are not available inside the function. Quote Link to comment https://forums.phpfreaks.com/topic/53239-solved-passing-vars-to-funtions/#findComment-263067 Share on other sites More sharing options...
siwelis Posted May 28, 2007 Author Share Posted May 28, 2007 Thank you much Chronister! Quote Link to comment https://forums.phpfreaks.com/topic/53239-solved-passing-vars-to-funtions/#findComment-263072 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.