Re[2]: [PHP] Globals

From: Date: Thu, 28 Dec 2000 21:56:47 +0000
Subject: Re[2]: [PHP] Globals
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-32163@lists.php.net to get a copy of this message
jb> Basically, if you want to use a variable in your main code, outside of jb> any functions withing any functions, you have to say: jb> global $var; // (where $var is the name of a variable you want to jb> // use withing that function) jb> inside of any function you want to use it in. This makes it so that jb> you can't accidentally change global vars inside of functions without jb> knowing it. So if I what to use the variables that are produces by this function below out side of the function I would have to declare them all global like global $domain,global $tld,etc,etc. Or am I totally wrong on this assumption. function getdata(){ $fp2=fopen ("userdata","r")or die("unable to open file ($userdata)"); flock($fp2, 2); //unless ($use_flock == 0); while ($data = fgetcsv ($fp2, 1000, ",")) { $num = count ($data); $row++; for ($c=0; $c<$num; $c++) { } $domain=$data[0]; $tld=$data[1]; $company=$data[2]; $userid=$data[3]; $firstname=$data[4]; $lastname=$data[5]; $address=$data[6]; $zip=$data[7]; $city=$data[8]; $telephone=$data[9]; $fax=$data[10]; $email=$data[11]; $package=$data[12]; $frontpage=$data[13]; $mysql=$data[14]; $change_registrar=$data[15]; } )

« previous php.general (#32163) next »