The filter_var_array() function is used to filter multiple variables.
Syntax
filter_var_array(arrayname, parameters)
Parameters
arrayname − An array to filter the data.
parameters − It specifies an array of filter arguments.
Return
The filter_var_array() function returns an array of values of the requested variables on success or false on failure.
Example
<?php $arr = Array ( "stname" => "Jack", "stmarks" => "95", "stemail" => "[email protected]", ); $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_var_array($arr, $filters)); ?>
The following is the output.
Array ( [stname] => Jack [stmarks] => 95 [stemail] => [email protected] )