您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php的一个神奇的技艺-用变量直接访问数组元素

2024/3/24 0:28:41发布20次查看
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;
//小结:即访问数组里的元素,直接可以用元素名访问
?
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product