|
Posted by Stephen Kay on 03/23/06 08:16
Sorry fi this is a stupid question - I come from a c/c++ background, and the
global variables in php aren't making sense to me.
If I want to declare a global variable, say in a global.php file, and have
it initialized to a certian value once, can that be done? Example:
// in global.php
$myvar = 25;
// in some other file
require ("global.php");
function somefunction()
{
global $myvar;
if ($myvar == 25){
$myvar = 30;
echo "setting myvar to 30.";
}
}
So far, so good. I can access this variable in this other functions.
But it doesn't seem to *stay* 30. It goes back to 25. Must be some other way
to do this in php, but I haven't come across the documentation yet. Thanks
for any info.
--
Stephen Kay
Karma-Lab sk@karma-lab.NOSPAM.com
^^^^^^^
Navigation:
[Reply to this message]
|