At 12:10 AM -0400 9/9/06, Robert Cummings wrote:
On Sat, 2006-09-09 at 12:57 +0900, Dave M G wrote:
PHP List,
I have a list of variables:
$001
$002
$003
$004
And what I'd like to do is have a function which will select and return
one of them. Something like:
public function returnVar($n)
{
return $(somehow n is made to reference the name of the variable);
}
And then in later scripts I can call anyone of the variables by saying
returnVar(001)
> Or something like that.
I've been scratching my head on how to do this for a while. I thought
the answer might lie somewhere in call_user_func(), but even if it is I
can't determine how.
Any advice would be much appreciated.
<?php
function easy_peasy( $name )
{
$foo1 = 1;
$foo2 = 2;
$foo3 = 3;
return $$name;
}
echo easy_peasy( 'foo2' )."\n";
?>
Cheers,
Rob.
Or something like that. <---- :-)
$easy_peasyier = array("foo1" => 1, "foo2" => 2, "foo3" => 3);
echo($easy_peasyier['foo1']);
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php