Re: Using a string from another function

From: Date: Mon, 06 Nov 2000 04:06:38 +0000
Subject: Re: Using a string from another function
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-23837@lists.php.net to get a copy of this message
Chris Aitken writes: > At 06:57 PM 5/11/2000, Joe Stump wrote: > >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'; > > } > >} > > > I had tried this first actually, and still no go. > > Whenever I call another function further in the php script, it doesnt know > the value of $color1 or $color2 It sounds like you're not using global in the receiving function--it needs to be used on any variable, inside any function, which it to be imported into the function's scope from the global scope. For instance, what does this code do for you? <?php error_reporting(E_ALL); function color_scheme($scheme) { global $color1, $color2; switch ($scheme) { case 1: $color1 = '#FFFFFF'; $color2 = '#000000'; break; case 2: $color1 = '#c300c3'; $color2 = '#000000'; break; default: /* default colors */ $color1 = '#c3c3c3'; $color2 = '#000000'; } } function table_stuff() { global $color1, $color2; echo "Doing table stuff with colors '$color1' and '$color2'.<br>\n"; } color_scheme(2); table_stuff(); ?> Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#23837) next »