在Php中,当一个数组的名称存储在一个变量中时调用它

时间:2010-03-17 01:32:40

标签: php arrays

  

可能重复:
  Convert a String to Variable

例如:

$ test = array(“this”,“is”,“a”,“test”);

$ what_array_to_read =“$ test [0]”;

函数读取数组$ test [0]

1 个答案:

答案 0 :(得分:4)

只有使用eval才能避免这种情况。

但如果你这样做

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

然后你可以访问

$$what_array_to_read[$what_index_to_read]; // will echo "this"