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