PHP filter_var_array() Function

PHP Filter Reference Complete PHP Filter Reference

Definition and Usage

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

This function is useful for filtering many values without calling filter_var() over and over.

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


filter_var_array(array, args)

Parameter Description
array Required. Specifies an array with string keys containing the data to filter
args Optional. Specifies an array of filter arguments. A valid array key is a variable name and a valid value is a filter ID, or an array specifying the filter, 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

A filter ID can be an ID name (like FILTER_VALIDATE_EMAIL) or an ID number (like 274)


Tips and Notes

Tip: Check the Complete PHP Filter Reference for possible filters to use with this function.


$arr = array
  "name" => "peter griffin",
  "age" => "41",
  "email" => "",

$filters = array
  "name" => array
  "age" => array

print_r(filter_var_array($arr, $filters));

The output of the code should be:

  [name] => Peter Griffin
  [age] => 41
  [email] =>

PHP Filter Reference Complete PHP Filter Reference


Color Picker