<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.filter-input-array" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>filter_input_array</refname>
  <refpurpose>Gets external variables and optionally filters them</refpurpose>
 </refnamediv>
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type class="union"><type>array</type><type>false</type><type>null</type></type><methodname>filter_input_array</methodname>
   <methodparam><type>int</type><parameter>type</parameter></methodparam>
   <methodparam choice="opt"><type class="union"><type>array</type><type>int</type></type><parameter>options</parameter><initializer><constant>FILTER_DEFAULT</constant></initializer></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>add_empty</parameter><initializer>&true;</initializer></methodparam>
  </methodsynopsis>
  <para>
   This function is useful for retrieving many values without
   repetitively calling <function>filter_input</function>.
  </para>
 </refsect1>
 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>type</parameter></term>
     <listitem>
      <para>
       One of <constant>INPUT_GET</constant>, <constant>INPUT_POST</constant>,
       <constant>INPUT_COOKIE</constant>, <constant>INPUT_SERVER</constant>, or
       <constant>INPUT_ENV</constant>.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>options</parameter></term>
     <listitem>
      <para>
       An array defining the arguments. A valid key is a <type>string</type>
       containing a variable name and a valid value is either a <link
       linkend="filter.filters">filter type</link>, or an <type>array</type>
       optionally specifying the filter, flags and options. If the value is an
       array, valid keys are <literal>filter</literal> which specifies the
       <link linkend="filter.filters">filter type</link>,
       <literal>flags</literal> which specifies any flags that apply to the
       filter, and <literal>options</literal> which specifies any options that
       apply to the filter. See the example below for a better understanding.
      </para>
      <para>
       This parameter can be also an integer holding a <link
       linkend="filter.constants">filter constant</link>. Then all values in the
       input array are filtered by this filter.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>add_empty</parameter></term>
     <listitem>
      <para>
       Add missing keys as &null; to the return value.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>
 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   An array containing the values of the requested variables on success.
   If the input array designated by <parameter>type</parameter> is not populated,
   the function returns &null; if the <constant>FILTER_NULL_ON_FAILURE</constant>
   flag is not given, or &false; otherwise. For other failures, &false; is returned.
  </para>
  <para>
   An array value will be &false; if the filter fails, or &null; if 
   the variable is not set. Or if the flag <constant>FILTER_NULL_ON_FAILURE</constant>
   is used, it returns &false; if the variable is not set and &null; if the filter 
   fails. If the <parameter>add_empty</parameter> parameter is &false;, no array
   element will be added for unset variables.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>A <function>filter_input_array</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php

/* data actually came from POST
$_POST = array(
    'product_id' => 'libgd<script>',
    'component'  => array('10'),
    'version'    => '2.0.33',
    'testarray'  => array('2', '23', '10', '12'),
    'testscalar' => '2',
);
*/

$args = array(
    'product_id'   => FILTER_SANITIZE_ENCODED,
    'component'    => array('filter'    => FILTER_VALIDATE_INT,
                            'flags'     => FILTER_REQUIRE_ARRAY, 
                            'options'   => array('min_range' => 1, 'max_range' => 10)
                           ),
    'version'      => FILTER_SANITIZE_ENCODED,
    'doesnotexist' => FILTER_VALIDATE_INT,
    'testscalar'   => array(
                            'filter' => FILTER_VALIDATE_INT,
                            'flags'  => FILTER_REQUIRE_SCALAR,
                           ),
    'testarray'    => array(
                            'filter' => FILTER_VALIDATE_INT,
                            'flags'  => FILTER_REQUIRE_ARRAY,
                           )

);

$myinputs = filter_input_array(INPUT_POST, $args);

var_dump($myinputs);
echo "\n";
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
array(6) {
  ["product_id"]=>
  string(17) "libgd%3Cscript%3E"
  ["component"]=>
  array(1) {
    [0]=>
    int(10)
  }
  ["version"]=>
  string(6) "2.0.33"
  ["doesnotexist"]=>
  NULL
  ["testscalar"]=>
  int(2)
  ["testarray"]=>
  array(4) {
    [0]=>
    int(2)
    [1]=>
    int(23)
    [2]=>
    int(10)
    [3]=>
    int(12)
  }
}
]]>
    </screen>
   </example>
  </para>
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    There is no <literal>REQUEST_TIME</literal> key in
    <constant>INPUT_SERVER</constant> array because it is inserted into the
    <varname>$_SERVER</varname> later.
   </para>
  </note>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>filter_input</function></member>
    <member><function>filter_var_array</function></member>
    <member><xref linkend="filter.filters"/></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
