Geekman Posted November 16, 2010 Share Posted November 16, 2010 I have a php script. I defined a variable outside of a function, but i cannot echo the variable inside the function. When I execute this: <?PHP $testvar = "test worked!"; testfunction(); function testfunction(){ echo $testvar; } ?> Nothing happens. what am i doing wrong. I did this on my local host. Apache running on Windows Vista Ultimate 32 bit Edition. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/218817-my-function-is-ignoring-variables/ Share on other sites More sharing options...
trq Posted November 16, 2010 Share Posted November 16, 2010 Functions have there own scope. You need to pass variables into them. function testfunction($str){ echo $str; } $testvar = "test worked!"; testfunction($testvar); Quote Link to comment https://forums.phpfreaks.com/topic/218817-my-function-is-ignoring-variables/#findComment-1134847 Share on other sites More sharing options...
Geekman Posted November 17, 2010 Author Share Posted November 17, 2010 So I have to include every single variable i need in the Parenthesis? Quote Link to comment https://forums.phpfreaks.com/topic/218817-my-function-is-ignoring-variables/#findComment-1135279 Share on other sites More sharing options...
trq Posted November 17, 2010 Share Posted November 17, 2010 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/218817-my-function-is-ignoring-variables/#findComment-1135281 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.