Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 6358

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>filter_var_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_list"
HREF="function.filter-list.html"><LINK
REL="NEXT"
TITLE="filter_var"
HREF="function.filter-var.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-list.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.filter-var.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.filter-var-array"
></A
>filter_var_array</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN55883"
></A
><P
>    (no version information, might be only in CVS)</P
>filter_var_array&nbsp;--&nbsp;Gets multiple variables and optionally filters them</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN55886"
></A
><H2
>说明</H2
>mixed <B
CLASS="methodname"
>filter_var_array</B
> ( array data [, mixed definition] )<BR
></BR
><P
>&#13;   This function is useful for retrieving many values without
   repetitively calling <A
HREF="function.filter-var.html"
><B
CLASS="function"
>filter_var()</B
></A
>.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN55899"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>data</CODE
></DT
><DD
><P
>&#13;       An array with string keys containing the data to filter.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>definition</CODE
></DT
><DD
><P
>&#13;       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
>&#13;       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="AEN55920"
></A
><H2
>返回值</H2
><P
>&#13;   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.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN55926"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN55929"
></A
><P
><B
>例 1. A <B
CLASS="function"
>filter_var_array()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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="#0000BB">$data </font><font color="#007700">= array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'product_id'&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#DD0000">'libgd&lt;script&gt;'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'component'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#DD0000">'10'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'versions'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#DD0000">'2.0.33'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'testscalar'&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; array(</font><font color="#DD0000">'2'</font><font color="#007700">, </font><font color="#DD0000">'23'</font><font color="#007700">, </font><font color="#DD0000">'10'</font><font color="#007700">, </font><font color="#DD0000">'12'</font><font color="#007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'testarray'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#DD0000">'2'</font><font color="#007700">,<br />);<br /><br /></font><font color="#0000BB">$args </font><font color="#007700">= array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'product_id'&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_SANITIZE_ENCODED</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'component'&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; array(</font><font color="#DD0000">'filter'&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'flags'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_FORCE_ARRAY</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'options'&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; array(</font><font color="#DD0000">'min_range' </font><font color="#007700">=&gt; </font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#DD0000">'max_range' </font><font color="#007700">=&gt; </font><font color="#0000BB">10</font><font color="#007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'versions'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_SANITIZE_ENCODED</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'doesnotexist' </font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'testscalar'&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'filter' </font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'flags'&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_REQUIRE_SCALAR</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'testarray'&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt; array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'filter' </font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_VALIDATE_INT</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'flags'&nbsp;&nbsp;</font><font color="#007700">=&gt; </font><font color="#0000BB">FILTER_FORCE_ARRAY</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br /><br />);<br /><br /></font><font color="#0000BB">$myinputs </font><font color="#007700">= </font><font color="#0000BB">filter_var_array</font><font color="#007700">(</font><font color="#0000BB">$data</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">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>array(6) {
  ["product_id"]=&#62;
  array(1) {
    [0]=&#62;
    string(17) "libgd%3Cscript%3E"
  }
  ["component"]=&#62;
  array(1) {
    [0]=&#62;
    int(10)
  }
  ["versions"]=&#62;
  array(1) {
    [0]=&#62;
    string(6) "2.0.33"
  }
  ["doesnotexist"]=&#62;
  NULL
  ["testscalar"]=&#62;
  bool(false)
  ["testarray"]=&#62;
  array(1) {
    [0]=&#62;
    int(2)
  }
}</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN55935"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.filter-input-array.html"
><B
CLASS="function"
>filter_input_array()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.filter-var.html"
><B
CLASS="function"
>filter_var()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.filter-input.html"
><B
CLASS="function"
>filter_input()</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-list.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-var.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>filter_list</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_var</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>