php的一个神奇的技巧--用变量直接访问数组元素
cmmon.inc.php
--------------------begin---------------------
foreach(array('_COOKIE', '_POST', '_GET','data') as $_request)
{
foreach($$_request as $_key => $_value)
{
$key{0} != '_' && $$_key = daddslashes($_value);
}
}
function daddslashes($string, $force = 0)
{
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
if(!MAGIC_QUOTES_GPC || $force)
{
if(is_array($string))
{
foreach($string as $key => $val)
{
$string[$key] = daddslashes($val, $force);
}
}
else
{
$string = addslashes($string);
}
}
return $string;
}
---------------------end---------------------------------------
index.php
-------------------------beign--------------
require_once 'common.inc.php';
//假设有一个路径请求 http://www.10086money.com?index.php&page=1&lang=cn,则可以如下取值方式
echo "page = ".$page;
echo "lang = ".$lang;
//小结:即访问数组里的元素,直接可以用元素名访问