- Forums
- PHP
- How Do You Declare Globals In Php Scripts
This Page Contains information about How Do You Declare Globals In Php Scripts By wallpaperama in category PHP with 1 Replies. [1174], Last Updated: Sat May 18, 2024
wallpaperama
Thu Oct 02, 2008
1 Comments
712 Visits
if you are here, you are wondering how you can use a variable through out the script.
if you are going to use a variable in a function for example this is how i would do it. for example:
$myname = 'wallpaperama';
function ShowMyName(){
return $myname ;
}
echo ShowMyName();
if you look at the code above, it would not work, you would have to call the string called $myname within the function so the code should look like this:
$myname = 'wallpaperama';
function ShowMyName(){
global $myname;
return $myname ;
}
echo ShowMyName();
another way you can declare globals are with $GLOBALS[]
for example:
$GLOBALS["myname] = "wallpaperama";
echo $GLOBALS["myname];
https://www.wallpaperama.com/forums/how-do-you-declare-globals-in-php-scripts-t6415.html