Re: Using a string from another function

From: Date: Mon, 06 Nov 2000 02:57:55 +0000
Subject: Re: Using a string from another function
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-23830@lists.php.net to get a copy of this message
You need to declare them global before you assign something to them. so do this: function color_scheme($scheme){ global $color1, $color2; if($scheme ==1){ $color1 = '#FFFFFF'; $color2 = '#000000'; } } --Joe On Mon, Nov 06, 2000 at 12:48:45PM +1100, Chris Aitken wrote: > Ive come across this problem and im not sure how to solve it. > > I have a file (stuff.inc) that has all my working and layout functions in > it. This file is included at the top of each php file using include() so I > can call on the functions.... > > All A-OK so far. > > What my concept is, I want to be able to specify a color scheme using one > of the functions. This function sets 2 variables........ > > function color_scheme($scheme) { > if ($scheme==1) { > $color1="#973100"; > $color2="#FEFFCA"; > } > global $color1, $color2; > } > > > > If I want to use $color1 or $color2 in my php file, its fine. But my > problem is, I use another function to generate a whole bunch of HTML table > output based on my outputted data and structured arrays. > > When I call this function, I cannot use $color1 or $color2 anymore. > > Is there a way to make a string not only globally usable for the php file > being processed, but from all included files as well ? > > > > > If I have left any info out, or can be more clear on something, please let > me know, but this one is baffling me. > > > > Chris > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ================================================================================ = Joe Stump joestump98@yahoo.com http://www.miester.org = ================================================================================ "Real programmers don't comment their code. It was hard to write, it should be hard to understand."

« previous php.general (#23830) next »