Home > Article > Backend Development > PHP filter_var_array example tutorial_PHP tutorial
Definition and usage
The filter_var_array() function gets multiple variables and their selected filter
This feature is useful for filtering many values without requiring filter_var(), much more.
Returns an array of values in the requested variable on success or FALSE on failure.
Grammar
filter_var_array(array, args)
<!--?php$arr = array ( "name" =-->"peter griffin", "age" => "41", "email" => "peter@example.com", );
$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));?>
输出结果.
Array ( [name] => Peter Griffin [age] => 41 [email] => peter@example.com )