<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.filter.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.filter-input-array.php',
    1 => 'filter_input_array',
    2 => 'Gets external variables and optionally filters them',
  ),
  'up' => 
  array (
    0 => 'ref.filter.php',
    1 => 'Filter Functions',
  ),
  'prev' => 
  array (
    0 => 'function.filter-input.php',
    1 => 'filter_input',
  ),
  'next' => 
  array (
    0 => 'function.filter-list.php',
    1 => 'filter_list',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/filter/functions/filter-input-array.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.filter-input-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">filter_input_array</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">filter_input_array</span> &mdash; <span class="dc-title">Gets external variables and optionally filters them</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.filter-input-array-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">function</span> <span class="methodname"><strong>filter_input_array</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$type</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code><a href="filter.constants.sanitization.php#constant.filter-default">FILTER_DEFAULT</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$add_empty</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span></span></div>

  <p class="para rdfs-comment">
   This function is useful for retrieving many values without
   repetitively calling <span class="function"><a href="function.filter-input.php" class="function">filter_input()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.filter-input-array-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">type</code></dt>
    <dd>
     <p class="simpara">
      One of the <strong><code><a href="filter.constants.input.php#constant.input-post">INPUT_<span class="replaceable">*</span></a></code></strong> constants.
     </p>
     <div class="warning"><strong class="warning">Warning</strong>
      <p class="simpara">
       The content of the superglobal that is being filtered is the original
       &quot;raw&quot; content provided by the <abbr title="Server Application Programming Interface">SAPI</abbr>,
       prior to any user modification to the superglobal.
       To filter a modified superglobal use
       <span class="function"><a href="function.filter-var-array.php" class="function">filter_var_array()</a></span> instead.
      </p>
     </div>
    </dd>
   
   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <p class="simpara">
      Either an associative <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of options,
      or the filter to apply to each entry,
      which can either be a validation filter by using one of the
      <strong><code><a href="filter.constants.validation.php#constant.filter-validate-bool">FILTER_VALIDATE_<span class="replaceable">*</span></a></code></strong>
      constants, or a sanitization filter by using one of the
      <strong><code><a href="filter.constants.sanitization.php#constant.filter-sanitize-string">FILTER_SANITIZE_<span class="replaceable">*</span></a></code></strong>
      constants.
     </p>
     <p class="simpara">
      The option array is an associative array where the key corresponds
      to a key in the input array and the associated
      value is either the filter to apply to this entry,
      or an associative array describing how and which filter should be
      applied to this entry.
     </p>
     <p class="simpara">
      The associative array describing how a filter should be applied
      must contain the <code class="literal">&#039;filter&#039;</code> key whose associated
      value is the filter to apply, which can be one of the
      <strong><code><a href="filter.constants.validation.php#constant.filter-validate-bool">FILTER_VALIDATE_<span class="replaceable">*</span></a></code></strong>,
      <strong><code><a href="filter.constants.sanitization.php#constant.filter-sanitize-string">FILTER_SANITIZE_<span class="replaceable">*</span></a></code></strong>,
      <strong><code><a href="filter.constants.sanitization.php#constant.filter-unsafe-raw">FILTER_UNSAFE_RAW</a></code></strong>, or
      <strong><code><a href="filter.constants.callback.php#constant.filter-callback">FILTER_CALLBACK</a></code></strong> constants.
      It can optionally contain the <code class="literal">&#039;flags&#039;</code> key
      which specifies any flags that apply to the filter,
      and the <code class="literal">&#039;options&#039;</code> key which specifies any options
      that apply to the filter.
     </p>
    </dd>
   
   
    <dt><code class="parameter">add_empty</code></dt>
    <dd>
     <p class="para">
      Add missing keys as <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> to the return value.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.filter-input-array-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   On success, an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> containing the values of the requested variables.
  </p>
  <p class="simpara">
   On failure, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned.
   If the input array designated by <code class="parameter">type</code> is not
   populated, <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> is returned instead.
  </p>
  <p class="simpara">
   Missing entries from the input array are added to the returned <span class="type"><a href="language.types.array.php" class="type array">array</a></span> as
   <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> if <code class="parameter">add_empty</code> is <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>,
   and are omitted entirely if it is <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
   Unlike <span class="function"><a href="function.filter-input.php" class="function">filter_input()</a></span>,
   the <strong><code><a href="filter.constants.flags.generic.php#constant.filter-null-on-failure">FILTER_NULL_ON_FAILURE</a></code></strong> flag does not change this:
   a missing entry is always <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
  </p>
  <p class="simpara">
   An entry of the returned <span class="type"><a href="language.types.array.php" class="type array">array</a></span> will be <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if the filter fails,
   unless the <strong><code><a href="filter.constants.flags.generic.php#constant.filter-null-on-failure">FILTER_NULL_ON_FAILURE</a></code></strong> flag is used,
   in which case it will be <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
   With the <strong><code><a href="filter.constants.flags.generic.php#constant.filter-force-array">FILTER_FORCE_ARRAY</a></code></strong> flag,
   that failure value is wrapped in a one element <span class="type"><a href="language.types.array.php" class="type array">array</a></span>
   like any other result.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.filter-input-array-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 A <span class="function"><strong>filter_input_array()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    This example assumes a GET request to
    <code class="literal">?email=user@example.com&amp;age=twenty&amp;url=https://example.com</code>.
    The <code class="literal">age</code> entry fails because <code class="literal">twenty</code> is
    not an integer; a value outside the
    <code class="literal">1</code> to <code class="literal">120</code> range would fail the same way.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
$filters </span><span style="color: #007700">= [
    </span><span style="color: #DD0000">'email' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">FILTER_VALIDATE_EMAIL</span><span style="color: #007700">,
    </span><span style="color: #DD0000">'age'   </span><span style="color: #007700">=&gt; [
        </span><span style="color: #DD0000">'filter'  </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">FILTER_VALIDATE_INT</span><span style="color: #007700">,
        </span><span style="color: #DD0000">'options' </span><span style="color: #007700">=&gt; [</span><span style="color: #DD0000">'min_range' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #DD0000">'max_range' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">120</span><span style="color: #007700">],
    ],
    </span><span style="color: #DD0000">'url'   </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">FILTER_VALIDATE_URL</span><span style="color: #007700">,
];

</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">filter_input_array</span><span style="color: #007700">(</span><span style="color: #0000BB">INPUT_GET</span><span style="color: #007700">, </span><span style="color: #0000BB">$filters</span><span style="color: #007700">);

</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(3) {
  [&quot;email&quot;]=&gt;
  string(16) &quot;user@example.com&quot;
  [&quot;age&quot;]=&gt;
  bool(false)
  [&quot;url&quot;]=&gt;
  string(19) &quot;https://example.com&quot;
}</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Example #2 Filtering POST data with <span class="function"><strong>filter_input_array()</strong></span></strong></p>
   <div class="example-contents"><p>
    This example assumes a POST request with fields
    <code class="literal">username=&lt;script&gt;alert&lt;/script&gt;</code> and
    <code class="literal">comment=Hello World</code>.
    No <code class="literal">missing</code> field is submitted: because
    <code class="parameter">add_empty</code> defaults to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, it is still present in
    the result, set to <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
$filters </span><span style="color: #007700">= [
    </span><span style="color: #DD0000">'username' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">FILTER_SANITIZE_SPECIAL_CHARS</span><span style="color: #007700">,
    </span><span style="color: #DD0000">'comment'  </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">FILTER_SANITIZE_SPECIAL_CHARS</span><span style="color: #007700">,
    </span><span style="color: #DD0000">'missing'  </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">FILTER_VALIDATE_INT</span><span style="color: #007700">,
];

</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">filter_input_array</span><span style="color: #007700">(</span><span style="color: #0000BB">INPUT_POST</span><span style="color: #007700">, </span><span style="color: #0000BB">$filters</span><span style="color: #007700">);

</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">array(3) {
  [&quot;username&quot;]=&gt;
  string(38) &quot;&amp;#60;script&amp;#62;alert&amp;#60;/script&amp;#62;&quot;
  [&quot;comment&quot;]=&gt;
  string(11) &quot;Hello World&quot;
  [&quot;missing&quot;]=&gt;
  NULL
}</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-3">
   <p><strong>Example #3 Requesting an input type that is not populated</strong></p>
   <div class="example-contents"><p>
    This example assumes a GET request.
    Because the request carried no POST fields,
    the input array designated by <strong><code><a href="filter.constants.input.php#constant.input-post">INPUT_POST</a></code></strong> is not
    populated and <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> is returned instead of an <span class="type"><a href="language.types.array.php" class="type array">array</a></span>.
    This applies to every input type:
    a request with no query string yields <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> for
    <strong><code><a href="filter.constants.input.php#constant.input-get">INPUT_GET</a></code></strong> as well.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">filter_input_array</span><span style="color: #007700">(</span><span style="color: #0000BB">INPUT_POST</span><span style="color: #007700">, [</span><span style="color: #DD0000">'a' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">FILTER_VALIDATE_INT</span><span style="color: #007700">]));
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">NULL</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.filter-input-array-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    There is no <code class="literal">REQUEST_TIME</code> key in
    <strong><code><a href="filter.constants.input.php#constant.input-server">INPUT_SERVER</a></code></strong> array because it is inserted into the
    <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER</a></var> later.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.filter-input-array-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.filter-input.php" class="function" rel="rdfs-seeAlso">filter_input()</a> - Gets a specific external variable by name and optionally filters it</span></li>
   <li><span class="function"><a href="function.filter-var.php" class="function" rel="rdfs-seeAlso">filter_var()</a> - Filters a variable with a specified filter</span></li>
   <li><span class="function"><a href="function.filter-var-array.php" class="function" rel="rdfs-seeAlso">filter_var_array()</a> - Gets multiple variables and optionally filters them</span></li>
   <li>
    Validation filters
    <strong><code><a href="filter.constants.validation.php#constant.filter-validate-bool">FILTER_VALIDATE_<span class="replaceable">*</span></a></code></strong>
   </li>
   <li>
    Sanitization filters
    <strong><code><a href="filter.constants.sanitization.php#constant.filter-sanitize-string">FILTER_SANITIZE_<span class="replaceable">*</span></a></code></strong>
   </li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>