Heim  >  Artikel  >  Backend-Entwicklung  >  变化变量_PHP教程

变化变量_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:26:48828Durchsuche

有些时候使用变化变量是十分方便的。也就是说,一个变量的名字将被动态的设置和使用。一个普通的变量将会使用如下的申明:
$a = "hello";
一个变化变量获得一个变量的值,并将其视该变量的名字。在上面的例子中,“hello”,能够使用变量的名字加上两个$来进行使用,例如。
$$a = "world";
在这一点上,两个变量被定义和存储在PHP的符号树上;$a的内容为“hello”,而$hello的值为“world”。因此如下的申明:
echo "$a ${$a}";
制作了和如下确切相同的输出:
echo "$a $hello";
他们都输出:“hello world”
要在数组中使用变化变量,您必须解决一个含糊的问题。它是:如果您写入了“$$a[1]”,然后解析程序将需要知道您想使用$a[1]作为变量还是使用$$a作为变量,这样索引“[1]”可能就会发生歧义。解决这种歧义的语法如下:“${$a[1]}”或者使用“${$a}[1]”(对上述的第二种情况)。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/531943.htmlTechArticle有些时候使用变化变量是十分方便的。也就是说,一个变量的名字将被动态的设置和使用。一个普通的变量将会使用如下的申明: $a = hel...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn