如下代码段:
<?php
foreach (array("_COOKIE","_POST","_GET") as $_request){
foreach ( $$_request as $key => $value ){
$$key = $value
}
}
?>
首先将数组("_COOKIE","_POST","_GET")赋给$_request,即 $_request = ("_COOKIE","_POST","_GET") 然后拼接成$$_request,表示通过方法$_COOKIE、$_POST、$_GET接收页面cookie、get、post的值 并将接收到的值赋给$key $value,就跟python的字典类似, "=>" 表示键key对应的值value 最后一句 $$key = $value 实现变量覆盖,将$key对应的变量覆盖,如:
<?php
$get_test = "imz";
$post_test = "ccm"
foreach (array("_COOKIE","_POST","_GET") as $_request){
foreach ( $$_request as $key => $value ){
$$key = $value;
}
}
echo "get_test:".$get_test."</br>";
echo "post_test:"