Lodius2000 Posted January 28, 2009 Share Posted January 28, 2009 to call a function defined in 1 function within the definition of another function you need a global line right ie <?php function blah(){ $a = "howdy world"; } function bleh(){ global $a; //prints howdy world print $a; } ?> sorry dumb question I know but its been a while for this sort of thing Thanks Link to comment https://forums.phpfreaks.com/topic/142747-solved-really-quick-variable-scope-question/ Share on other sites More sharing options...
ratcateme Posted January 28, 2009 Share Posted January 28, 2009 <?php function blah(){ $a = "howdy world"; } function bleh(){ global $a; //prints howdy world print $a; } bleh(); will output nothing as $a is local to blah and not global to the whole script <?php function blah(){ global $a; $a = "howdy world"; } function bleh(){ global $a; //prints howdy world print $a; } bleh(); will still not work because the value of $a is never set even though it is global in both in functions but: <?php function blah(){ global $a; $a = "howdy world"; } function bleh(){ global $a; //prints howdy world print $a; } blah(); bleh(); will output "howdy world" because the global variable $a is set in blah() then read in bleh() Scott. Link to comment https://forums.phpfreaks.com/topic/142747-solved-really-quick-variable-scope-question/#findComment-748253 Share on other sites More sharing options...
Lodius2000 Posted January 28, 2009 Author Share Posted January 28, 2009 gotcha Link to comment https://forums.phpfreaks.com/topic/142747-solved-really-quick-variable-scope-question/#findComment-748256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.