如何在PHP中将字符串(变量名称)转换为变量?

如何在PHP中将字符串(变量名称)转换为变量?,php,string,variables,Php,String,Variables,是否可以使用字符串作为实际变量名? 这样说: $a = '$myvariable[\'subitem\']'; 如何转换变量$a,以便实际使用变量 $myvariable['subitem'] ? 例如: $myvariable['subitem'] = "hello"; $a = '$myvariable[\'subitem\']'; // do somenthing with $a echo $a // outputs "hello" instead of $myvariable

是否可以使用字符串作为实际变量名? 这样说:

$a = '$myvariable[\'subitem\']';
如何转换变量
$a
,以便实际使用变量

$myvariable['subitem'] ?
例如:

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

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

// do somenthing with $a

echo $a  // outputs "hello" instead of $myvariable['subitem']
这个怎么样:

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

如果希望变量名为
$myvariable['subitem']
,使用
$item='subitem'有什么问题$myarray[$item]
?(我不清楚目标。)我想你没有理解我的意思。你是说$$a=“新的东西”;$a应该只包含变量的名称。。我的意思是使用字符串(表示变量名称)来获取实际变量。@totalma使用$$a,就像我描述的那样。试试我的答案