Re: construct name variable

From: Date: Tue, 06 Nov 2001 16:27:49 +0000
Subject: Re: construct name variable
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-10239@lists.php.net to get a copy of this message
What do you mean "return $b_example"? Do you mean return that as a string? When a function returns a value, it just returns a value -- a nameless value. It doesn't matter what the variable was called within the function, it just returns the value, without any variable name. However, you *could* have a function set a global variable with the desired name and value. The following function will do that: create a global variable named $a_sample with the value that you provided. May be this is what you want? If not, please be more specific... function make_variable($id, $value) {
    $thevar = $id.'_example';
    global $$thevar;
    $$thevar = $value;
} make_variable('a', 5); echo "a_example: $a_example<br>\n"; // This displays 5, as it should... At 09:47 AM 11/6/2001 +0100, you wrote:
hallo all, I woul like to construct the name of my variables using a function. for example, when I call the function using 'a' as an input it will return the variable $a_example with some value. When I call the function using 'b' as an input it will return $b_example. I have no idea how to do this. Can somebody help me with this one? kind regards, Pim
              -=- Mike Flynn - Burlington, VT -=-
mike@mikeflynn.net http://www.mikeflynn.net/ * Give blood * ...maintaining lawns, watching televised sports, birthing children, listening to Top 40 music, and collecting stuffed animals...

« previous php.windows (#10239) next »