Home  >  Article  >  Backend Development  >  ${$key}这段代码是什么意思

${$key}这段代码是什么意思

WBOY
WBOYOriginal
2016-06-23 13:12:041648browse

$globals = array($_REQUEST, $_SESSION, $_SERVER, $_FILES);foreach($globals as $global){    foreach(array_keys($global) as $key){        unset(${$key});    }}


 unset(${$key});这行代码是怎么执行成功的,我没有理解呀,


回复讨论(解决方案)

见手册:可变变量

见手册:可变变量



我也看了手册,不知道什么时候使用,我做的demo执行不成功,例子如下:
$globals = array(array('param1'=>'PRC','param'=>'USA'));foreach($globals as $global){    foreach(array_keys($global) as $key){        unset(${$key});    }}

你给的例子没有多大意义,这才是惯常的用法

$a = 1;$b = 2;$c = 3;foreach(array('a', 'b', 'c') as $k) echo ${$k};
123

你给的例子没有多大意义,这才是惯常的用法

$a = 1;$b = 2;$c = 3;foreach(array('a', 'b', 'c') as $k) echo ${$k};
123



嗯嗯,好的,谢谢
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn