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

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

WBOY
WBOYOriginal
2016-06-13 13:12:08865browse

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;

//小结:即访问数组里的元素,直接可以用元素名访问


?

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