Re: Using a string from another function
| From: | Chris Aitken | Date: | Mon, 06 Nov 2000 03:52:49 +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-23833@lists.php.net to get a copy of this message | ||
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
For example, here is the basic rundown of how I do it...............
------------------------------------------------------------------------
functions.inc
function color_scheme {
assigns the $color1 and $color2 and sets globally;
based on the assigned value from the main php file
}
function table_stuff {
called by the main php file, with an array of data;
also uses both $color1 and $color2 in its function;
}
-------------------------------------------------------------------------
main.php
<?
include("functions.inc")
//sets the color scheme to 1's values
color_scheme(1);
//lays out the table data as per the function. This function is supposed
//to call on the previously set global values of $color1 and $color2
table_stuff(array("blah blah","more blah"));
?>
--------------------------------------------------------------------------
In a nutshell, thats the desired effect. From the main file, firstly set the color scheme and make the values global, then run any other functions and make the color scheme values available to all other functions if needed.
Chris