Home > Article > Backend Development > filter_input_array() function in PHP
filter_input_array() function gets the names of external variables and optionally filters them.
filter_input_array(type, arraydefine, add_empty)
type - There are five types of input to check, namely INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
arraydefine - It specifies an array of filter parameters. This is optional.
add_empty - If True, missing keys will be added to the return value as NULL.
filter_input_array() function returns an array containing variable values on success and false on failure.
The following is an example of using the filter_input_array() function to filter the POST variables stname (student name), stmarks (student score), 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] => jack@abcde.com )
The above is the detailed content of filter_input_array() function in PHP. For more information, please follow other related articles on the PHP Chinese website!