【发布时间】:2017-02-05 23:07:47
【问题描述】:
早安,
我目前正在尝试弄清楚如何使用存储在变量中的字符来按名称调用另一个变量。例如:
$string = "ABCD";
$A = 10;
echo //Here I want to get $string[0]'s value, which will be A, then echo the value of the variable named after $string[0]'s value, $A. So in other words the output of the echo should be 10.
如果我对这个问题不够清楚,请告诉我。
【问题讨论】:
-
echo ${$string[0]};? -
逻辑叫做variables of variable,这里@Darren是对的。
-
小心变量变量,因为它们几乎从不产生干净、可维护的代码。除了纯粹的学术代码,您应该尽可能避免使用它们。