Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP filter_input_array() Function

PHP filter_input_array() Function


PHP Filter Reference Manual Complete PHP Filter Reference Manual


Definition and Usage

The filter_input_array() function gets multiple inputs from outside the script (such as form input) and filters them.

This function is useful for filtering multiple input variables without repeatedly calling filter_input().

This function can get input from a variety of sources:

Returns the filtered data as an array on success, or FALSE on failure.

Syntax

filter_input_array(input_type, filter_args)

Parameters Description
input_type Required. Specifies the input type. See the list of possible types above.
filter_args Optional. Specifies an array of filter arguments. Valid array keys are variable names, and valid values are filter IDs or arrays specifying the filter, flags, and options.

This parameter can also be a single filter ID, in which case all values in the input array are filtered by the specified filter.

A filter ID can be an ID name (such as FILTER_VALIDATE_EMAIL) or an ID number (such as 274).


Tips and Notes

**Tip:** See Complete PHP Filter Reference Manualfor the filters that can be used with this function.


Example

In this example, we use the filter_input_array() function to filter three POST variables. The POST variables received are name, age, and e-mail address:

array ( "filter"=>FILTER_CALLBACK, "flags"=>FILTER_FORCE_ARRAY, "options"=>"ucwords" ), "age" => array ( "filter"=>FILTER_VALIDATE_INT, "options"=>array ( "min_range"=>1, "max_range"=>120 ) ), "email"=> FILTER_VALIDATE_EMAIL, ); print_r(filter_input_array(INPUT_POST, $filters)); ?>

The output of the code is shown below:

Array

(

[name] => Peter

[age] => 41

[email] => peter@example.com

)


PHP Filter Reference Manual Complete PHP Filter Reference Manual