AV1611 Posted September 25, 2007 Share Posted September 25, 2007 If I create a $var $myvar="some string"; then I make a function: function myfunction();{ ... }; what do I have to do to be able to use $myvar from within the function? Link to comment https://forums.phpfreaks.com/topic/70554-solved-var-in-function/ Share on other sites More sharing options...
AV1611 Posted September 25, 2007 Author Share Posted September 25, 2007 Never mind global $myvar; Link to comment https://forums.phpfreaks.com/topic/70554-solved-var-in-function/#findComment-354523 Share on other sites More sharing options...
pocobueno1388 Posted September 25, 2007 Share Posted September 25, 2007 Pass it as a parameter of the function. <?php function myFunc($var){ echo $var; } $str = "Blaaaaah"; myFunc($str); ?> Link to comment https://forums.phpfreaks.com/topic/70554-solved-var-in-function/#findComment-354525 Share on other sites More sharing options...
trq Posted September 25, 2007 Share Posted September 25, 2007 Globals are bad. <?php $myvar = "some string"; function myfunction($v) { echo $v; } myfunction($myvar); ?> Link to comment https://forums.phpfreaks.com/topic/70554-solved-var-in-function/#findComment-354528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.