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

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

WBOY
Release: 2016-06-23 13:12:04
Original
1695 people have browsed it

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


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


回复讨论(解决方案)

见手册:可变变量

见手册:可变变量



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

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

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

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

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



嗯嗯,好的,谢谢
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template