Hyaku_ Posted December 28, 2006 Share Posted December 28, 2006 Hi!How can I define a variable, so that it can be accessed from a function? For example:first_page.php[code]$global_variable = 10;include('funct.php');[/code]funct.php:[code]function echo_global_variable(){echo $global_variable;}[/code]Thanks! Link to comment https://forums.phpfreaks.com/topic/32120-global-variables-so-functions-can-access-them/ Share on other sites More sharing options...
onlyican Posted December 28, 2006 Share Posted December 28, 2006 [code]<?php$myname = "Jamie";function MyFunction(){global $myname;echo $myname;}MyFunction();//You just need to add global before the variable?>[/code] Link to comment https://forums.phpfreaks.com/topic/32120-global-variables-so-functions-can-access-them/#findComment-149046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.