Forum Moderators: coopster

Message Too Old, No Replies

create a variable?

create a variable?

         

drooh

3:13 am on May 28, 2009 (gmt 0)

10+ Year Member



Is it possible to do something like this?

$file = "file2";
${$file}_er = "something";
OR
$.$file."_er" = "something";

I want to create $file2_er using the variable $file

How would i go about doing this?

eelixduppy

3:18 am on May 28, 2009 (gmt 0)



It is certainly possible to do such a thing. It's called variable variables [php.net].

Try your first example and play around with it a bit until it works as you want.

drooh

12:35 pm on May 28, 2009 (gmt 0)

10+ Year Member



I had already looked into variable variables but i did not see any indication that i could concatenate on to it?

coopster

12:56 pm on May 28, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$file = 'file2'; 
${"{$file}_er"} = 'something';
print $file2_er;

drooh

1:09 pm on May 28, 2009 (gmt 0)

10+ Year Member



This seems to work too

${$file.'_er'} = "something";

coopster

1:28 pm on May 28, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, that will work too. There are many ways to parse and concatenate strings [php.net].