The filter_input_array() function gets names of external variables and filters them optionally.
Syntax
filter_input_array(type, arraydefine, add_empty)
Parameters
type − There are five types of inputs to check i.e. INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
arraydefine − It specifies an array of filter arguments. It is optional.
add_empty − If value is True, it adds missing keys as NULL to the return value.
Return
The filter_input_array() function returns an array containing the values of the variables on success, or false on failure.
Example
The following is an example that use the filter_input_array() function to filter POST variables stname (student name), stmarks (student marks), stemail (student email)
<?php $filters = array ( "stname" => array ( "filter"=>FILTER_CALLBACK, "flags"=>FILTER_FORCE_ARRAY, "options"=>"ucwords" ), "stmarks" => array ( "filter"=>FILTER_VALIDATE_INT, "options"=>array ( "min_range"=>1, "max_range"=>100 ) ), "stemail"=> FILTER_VALIDATE_EMAIL, ); print_r(filter_input_array(INPUT_POST, $filters)); ?>
The following is the output.
Array ( [stname] => Jack [stmarks] => 95 [stemail] => [email protected] )