filter_input_array()

filter_input_array() — Gets external variables and optionally filters them.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.2.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

This function is useful for retrieving many values without repetitively calling filter_input().

Signature

filter_input_array(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null

Parameters

ParameterTypeWhat it takes
$typeintOne of the INPUT_* constants.
$optionsarray|intEither an associative array of options, or the filter to apply to each entry, which can either be a validation filter by using one of the FILTER_VALIDATE_* constants, or a sanitization filter by using one of the FILTER_SANITIZE_* constants.
$add_emptyboolAdd missing keys as null to the return value.

Return value

On success, an array containing the values of the requested variables. On failure, false is returned. If the input array designated by type is not populated, null is returned instead. Missing entries from the input array are added to the returned array as null if add_empty is true, and are omitted entirely if it is false. Unlike filter_input(), the FILTER_NULL_ON_FAILURE flag does not change this: a missing entry is always null. An entry of the returned array will be false if the filter fails, unless the FILTER_NULL_ON_FAILURE flag is used, in which case it will be null. With the FILTER_FORCE_ARRAY flag, that failure value is wrapped in a one element array like any other result.

Example

A runnable snippet:

$filters = [ 'email' => FILTER_VALIDATE_EMAIL, 'age' => [ 'filter' => FILTER_VALIDATE_INT, 'options' => ['min_range' => 1, 'max_range' => 120], ], 'url' => FILTER_VALIDATE_URL, ]; $result = filter_input_array(INPUT_GET, $filters); var_dump($result);

Output:

array(3) { ["email"]=> string(16) "user@example.com" ["age"]=> bool(false) ["url"]=> string(19) "https://example.com" }

See also

filter_input(), filter_var(), filter_var_array()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page filter_input_array() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.