gotornot Posted October 7, 2009 Share Posted October 7, 2009 Hi I am trying to write an email function and ive hit a snag I need to assign 2 variables in the function with the content of an html email and text email. Is there anyway of declairing a variiable within a function for use outside of it in the code below? Link to comment https://forums.phpfreaks.com/topic/176808-how-do-i-assign-a-variable-in-a-function-for-use-outside-of/ Share on other sites More sharing options...
Garethp Posted October 7, 2009 Share Posted October 7, 2009 http://au2.php.net/manual/en/language.variables.scope.php Look to the section that describes the global keyword Link to comment https://forums.phpfreaks.com/topic/176808-how-do-i-assign-a-variable-in-a-function-for-use-outside-of/#findComment-932218 Share on other sites More sharing options...
gotornot Posted October 7, 2009 Author Share Posted October 7, 2009 i cant find anything in the code can you point me out somewhere? Link to comment https://forums.phpfreaks.com/topic/176808-how-do-i-assign-a-variable-in-a-function-for-use-outside-of/#findComment-932223 Share on other sites More sharing options...
Garethp Posted October 7, 2009 Share Posted October 7, 2009 Seriously, you just have to scroll down a little bit $a = 1; $b = 2; function Sum() { global $a, $b; $b = $a + $b; } Sum(); echo $b; ?> Link to comment https://forums.phpfreaks.com/topic/176808-how-do-i-assign-a-variable-in-a-function-for-use-outside-of/#findComment-932229 Share on other sites More sharing options...
trq Posted October 7, 2009 Share Posted October 7, 2009 You are actually much better off having your function return a value it has worked on. eg; function foo($a) { return $a; } $a = foo("bar"); echo $a; Link to comment https://forums.phpfreaks.com/topic/176808-how-do-i-assign-a-variable-in-a-function-for-use-outside-of/#findComment-932234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.