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? 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. 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! 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
Archived
This topic is now archived and is closed to further replies.