filter_input_arrayGets external variables and optionally filters them Description
arrayfalsenull filter_input_array(int
$type, arrayint $options = FILTER_DEFAULT, bool $add_empty = true)This function is useful for retrieving many values without repetitively calling filter_input. Parameters
Return ValuesOn success, an array containing the values of the requested variables.
On failure,
Missing entries from the input array are added to the returned array as
An entry of the returned array will be Errors/Exceptions
Throws a ValueError if
If the input array designated by
As of PHP 8.5.0, throws a
Filter\FilterFailedException if the
Changelog
ExamplesExample #1 A filter_input_array example
This example assumes a GET request to
The above example will output something similar to:
array(3) {
["email"]=>
string(16) "user@example.com"
["age"]=>
bool(false)
["url"]=>
string(19) "https://example.com"
}
Example #2 Filtering POST data with filter_input_array
This example assumes a POST request with fields
The above example will output something similar to:
array(3) {
["username"]=>
string(38) "<script>alert</script>"
["comment"]=>
string(11) "Hello World"
["missing"]=>
NULL
}
Example #3 Requesting an input type that is not populated
This example assumes a GET request.
Because the request carried no POST fields,
the input array designated by The above example will output something similar to: NULL Notes
See Also
|