<?php
function fetch_from_array(&$arr,$index=null,$xss_clean=false)
{
isset($index) or $index=array_keys($arr);
if(is_array($index))
{
$output=array();
foreach($index as $key)
{
$output[$key]=fetch_from_array($arr,$key,$xss_clean);
}
return $output;
}
if(isset($arr[$index]))
{
$value=$arr[$index];
}
elseif(($count=preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/',$index,$matches))>1)
{
$value=$arr;
for($i=0;$i<$count;$i++)
{
$key=trim($matches[0][$i],'[]');
if($key==='')
{
break;
}
if(isset($value[$key]))
{
$value=$value[$key];
}else
{
return null;
}
}
}else
{
return null;
}
return $value;
}
?>
<html>
<meta http-equiv="content-type";content="text/html";charset="utf-8">
<head>
<title>测试GET提交</title>
</head>
<body>
<div>
<form id="form1" action="" method="get">
First Name : <input type="text" name="fname"><br/>
Last Name : <input type="text" name="lname"><br/>
Password  : <input type="password" name="pwd"><br/>
<div id="sub"><input type="submit" value="提交"></div>
</form>
</div>
</body>
</html>
<?php
$data=array();
$data=fetch_from_array($_GET,['fname','lname','pwd'],false);
echo implode(',',$data);
?>