The filter_var_array() function obtains multiple variables and filters them.
This function is useful for filtering multiple values without repeatedly calling filter_var().
If successful, returns the value of the request variable as an array. If it fails, returns FALSE.
filter_var_array(array, args)
parameter | describe |
---|---|
array | Required. Specifies an array with string keys containing the data to filter. |
args | Optional. Specifies an array of filter parameters. Legal array keys are variable names, and legal values are filter IDs, or arrays specifying filters, flags, and options. This parameter can also be a single filter ID, if so, all values in the input array are filtered by the specified filter. The filter ID can be an ID name (such as FILTER_VALIDATE_EMAIL) or an ID number (such as 274). |
Tip: See the complete PHP Filter reference manual to see the filters that can be used with this function.
<?php$arr = array ( "name" => "peter griffin", "age" => "41", "email" => "[email protected]", );$filters = array ( "name" => 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_var_array($arr, $filters)) ;?>
The output of the code looks like this:
Array ( [name] => Peter Griffin [age] => 41 [email] => [email protected] )