On Fri, 16 Nov 2001, Jeff Lewis wrote:

> What I need to do, however, is append a variable portion to a constant prefix.  So I 
>have a set of variables that are named $MYdog, $MYcat etc. and I need to do
>
> $a = "dog"
> ${"MY$a"} being the same as $MYdog
>
> Can this be done, and if so - how? I can't get it to work.

So what you want is a base name with a vaiably-changing portion
concatenated?  Gotcha!

// you variable base name
$myVarBase = "MY";

$a = cat;
$something1 = "This Var Likes Cats";

$b = dog;
$something2 = "This Var Likes Dogs";

$myVarName1 = $myVarBase . $a;
$myVarName2 = $myVarBase . $b;

// The same as $Mycat = "This Var Likes Cats";
${$myVarName1} = $something1;

// The same as $Mydog = "This Var Likes Dogs";
${$myVarName2} = $something2;


        g.luck
        ~Chris                           /"\
                                         \ /     September 11, 2001
                                          X      We Are All New Yorkers
                                         / \     rm -rf /bin/laden


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to