Reply to how do you initialize global variables once?

Your name:

Reply:


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
^^^^^^^

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация