PHP filter_var_array() Function

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.filter_var_array — Gets multiple variables and optionally filters them.

mixed filter_var_array ( array $data [, mixed $definition [, bool $add_empty = TRUE ]] )

This function is useful for retrieving many values without repetitively calling filter_var().

An array containing the values of the requested variables on success, or FALSE on failure. An array value will be FALSE if the filter fails, or NULL if the variable is not set.

Example -

The above example will output : -

array(6) {
  ["product_id"]=>
  string(17) "libgd%3Cscript%3E"
  ["component"]=>
  array(1) {
    [0]=>
    int(10)
  }
  ["versions"]=>
  string(6) "2.0.33"
  ["doesnotexist"]=>
  NULL
  ["testscalar"]=>
  bool(false)
  ["testarray"]=>
  array(1) {
    [0]=>
    int(2)
  }
}

ParameterDescription
arraySpecifies an array with string keys containing the data to filter
argsSpecifies 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)