Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP filter_var_array() Function

PHP filter_var_array() Function


PHP Filter Reference Manual Complete PHP Filter Reference Manual


Definition and Usage

The filter_var_array() function gets multiple variables and filters them.

This function is useful for filtering multiple values without repeatedly calling filter_var().

Returns the values of the requested variables as an array on success, or FALSE on failure.

Syntax

filter_var_array(array, args)

Parameters Description
array Required. Specifies an array with string keys containing the data to filter.
args Optional. Specifies an array of filter arguments. Valid array keys are variable names, and valid values are filter IDs or arrays specifying the filter, flags, and options.

This parameter can also be a single filter ID, in which case all values in the input array are filtered by the specified filter.

A filter ID can be an ID name (such as FILTER_VALIDATE_EMAIL) or an ID number (such as 274).


Tips and Notes

**Tip:** See Complete PHP Filter Reference Manualfor the filters that can be used with this function.


Example

"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)); ?>

The output of the code is shown below:

Array

(

[name] => Peter Griffin

[age] => 41

[email] => peter@example.com

)


PHP Filter Reference Manual Complete PHP Filter Reference Manual