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.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to