0

Possible duplicate:
Convert a String to Variable

for example:

$test = array("this","is","a","test");

$what_array_to_read = "$test[0]";

function to read the array $test[0]

2
  • 3
    This is very similar to this question: stackoverflow.com/questions/433302/… On a personal note, if you need to do this, IMHO you're doing something wrong. What's the use case for this? Commented Mar 17, 2010 at 1:36
  • maybe you want to stuff your arrays into a hash. Commented Mar 17, 2010 at 1:37

1 Answer 1

4

That is only possible using eval which should be avoided.

But if you do

$what_array_to_read = "test";
$what_index_to_read = 0;

then you can access

$$what_array_to_read[$what_index_to_read]; // will echo "this"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.