<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >filter_input_array</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="Filter Functions" HREF="ref.filter.html"><LINK REL="PREVIOUS" TITLE="filter_id" HREF="function.filter-id.html"><LINK REL="NEXT" TITLE="filter_input" HREF="function.filter-input.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.filter-id.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.filter-input.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.filter-input-array" ></A >filter_input_array</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN55708" ></A ><P > (no version information, might be only in CVS)</P >filter_input_array -- Gets multiple variables from outside PHP and optionally filters them</DIV ><DIV CLASS="refsect1" ><A NAME="AEN55711" ></A ><H2 >说明</H2 >mixed <B CLASS="methodname" >filter_input_array</B > ( int type [, mixed definition] )<BR ></BR ><P > This function is useful for retrieving many values without repetitively calling <A HREF="function.filter-input.html" ><B CLASS="function" >filter_input()</B ></A >. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN55724" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >type</CODE ></DT ><DD ><P > One of <TT CLASS="constant" ><B >INPUT_GET</B ></TT >, <TT CLASS="constant" ><B >INPUT_POST</B ></TT >, <TT CLASS="constant" ><B >INPUT_COOKIE</B ></TT >, <TT CLASS="constant" ><B >INPUT_SERVER</B ></TT >, <TT CLASS="constant" ><B >INPUT_ENV</B ></TT >, <TT CLASS="constant" ><B >INPUT_SESSION</B ></TT >, or <TT CLASS="constant" ><B >INPUT_REQUEST</B ></TT >. </P ></DD ><DT ><CODE CLASS="parameter" >definition</CODE ></DT ><DD ><P > An array defining the arguments. A valid key is a <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A > containing a variable name and a valid value is either a filter type, or an <A HREF="language.types.array.html" ><B CLASS="type" >array</B ></A > optionally specifying the filter, flags and options. If the value is an array, valid keys are <TT CLASS="literal" >filter</TT > which specifies the filter type, <TT CLASS="literal" >flags</TT > which specifies any flags that apply to the filter, and <TT CLASS="literal" >options</TT > which specifies any options that apply to the filter. See the example below for a better understanding. </P ><P > This parameter can be also an integer holding a <A HREF="ref.filter.html#filter.intro" >filter constant</A >. Then all values in the input array are filtered by this filter. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN55752" ></A ><H2 >返回值</H2 ><P > An array containing the values of the requested variables on success, or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. An array value will be <TT CLASS="constant" ><B >FALSE</B ></TT > if the filter fails, or <TT CLASS="constant" ><B >NULL</B ></TT > if the variable is not set. Or if the flag <TT CLASS="constant" ><B >FILTER_NULL_ON_FAILURE</B ></TT > is used, it returns <TT CLASS="constant" ><B >FALSE</B ></TT > if the variable is not set and <TT CLASS="constant" ><B >NULL</B ></TT > if the filter fails. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN55761" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN55764" ></A ><P ><B >例 1. A <B CLASS="function" >filter_input_array()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />error_reporting</font><font color="#007700">(</font><font color="#0000BB">E_ALL </font><font color="#007700">| </font><font color="#0000BB">E_STRICT</font><font color="#007700">);<br /></font><font color="#FF8000">/* data actually came from POST<br />$_POST = array(<br /> 'product_id' => 'libgd<script>',<br /> 'component' => '10',<br /> 'versions' => '2.0.33',<br /> 'testscalar' => array('2', '23', '10', '12'),<br /> 'testarray' => '2',<br />);<br />*/<br /><br /></font><font color="#0000BB">$args </font><font color="#007700">= array(<br /> </font><font color="#DD0000">'product_id' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_SANITIZE_ENCODED</font><font color="#007700">,<br /> </font><font color="#DD0000">'component' </font><font color="#007700">=> array(</font><font color="#DD0000">'filter' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br /> </font><font color="#DD0000">'flags' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_FLAG_ARRAY</font><font color="#007700">, <br /> </font><font color="#DD0000">'options' </font><font color="#007700">=> array(</font><font color="#DD0000">'min_range' </font><font color="#007700">=> </font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#DD0000">'max_range' </font><font color="#007700">=> </font><font color="#0000BB">10</font><font color="#007700">)<br /> ),<br /> </font><font color="#DD0000">'versions' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_SANITIZE_ENCODED</font><font color="#007700">,<br /> </font><font color="#DD0000">'doesnotexist' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br /> </font><font color="#DD0000">'testscalar' </font><font color="#007700">=> array(<br /> </font><font color="#DD0000">'filter' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br /> </font><font color="#DD0000">'flags' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_FLAG_SCALAR</font><font color="#007700">,<br /> ),<br /> </font><font color="#DD0000">'testarray' </font><font color="#007700">=> array(<br /> </font><font color="#DD0000">'filter' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br /> </font><font color="#DD0000">'flags' </font><font color="#007700">=> </font><font color="#0000BB">FILTER_FLAG_ARRAY</font><font color="#007700">,<br /> )<br /><br />);<br /><br /></font><font color="#0000BB">$myinputs </font><font color="#007700">= </font><font color="#0000BB">filter_input_array</font><font color="#007700">(</font><font color="#0000BB">INPUT_POST</font><font color="#007700">, </font><font color="#0000BB">$args</font><font color="#007700">);<br /><br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$myinputs</font><font color="#007700">);<br />echo </font><font color="#DD0000">"\n"</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >上例将输出:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >array(6) { ["product_id"]=> array(1) { [0]=> string(17) "libgd%3Cscript%3E" } ["component"]=> array(1) { [0]=> int(10) } ["versions"]=> array(1) { [0]=> string(6) "2.0.33" } ["doesnotexist"]=> NULL ["testscalar"]=> bool(false) ["testarray"]=> array(1) { [0]=> int(2) } }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN55770" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.filter-input.html" ><B CLASS="function" >filter_input()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.filter-var-array.html" ><B CLASS="function" >filter_var_array()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.filter-id.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.filter-input.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >filter_id</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.filter.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >filter_input</TD ></TR ></TABLE ></DIV ></BODY ></HTML >