-2

Is it somehow possible to use a string as an actual variable name? Sothing like this:

$a = '$myvariable[\'subitem\']';

How can I convert variable $a in order to actually work with a variable

$myvariable['subitem'] ?

EXAMPLE:

$myvariable['subitem'] = "hello";

$a = '$myvariable[\'subitem\']';

// do somenthing with $a

echo $a  // outputs "hello" instead of $myvariable['subitem']
2
  • You want the variable name to be the value of $myvariable['subitem']? Commented Jun 4, 2014 at 21:06
  • What's wrong with using $item = 'subitem'; $myarray[$item]? (The goal is unclear to me.) Commented Jun 4, 2014 at 21:11

1 Answer 1

0

how about this:

$a = 'myvariable["subitem"]';
echo $$a;

Above is called variable variables

Sign up to request clarification or add additional context in comments.

10 Comments

I think you dont get me right..
You mean $$a = "something new";
the $a is supposed to contain just a name of a varible..
I mean to use strings (that represent the names of variables) to get the actual variables..
@Totallama use $$a like I described. Try my answer
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.