PHP filter_input_array() Function

The filter_input_array() function gets external variables (e.g. from form input) and optionally filters them.This function is useful for retrieving/filtering many values instead of calling filter_input() many times.filter_input_array — Gets external variables and optionally filters them.

mixed filter_input_array ( int $type [, mixed $definition [, bool $add_empty = TRUE ]] )

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

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. Or if the flag FILTER_NULL_ON_FAILURE is used, it returns FALSE if the variable is not set and NULL if the filter fails.

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
typeOne of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.
definitionAn array defining the arguments. A valid key is a string containing a variable name and a valid value is either a filter type, or an array optionally specifying the filter, flags and options. If the value is an array, valid keys are filter which specifies the filter type, flags which specifies any flags that apply to the filter, and options which specifies any options that apply to the filter. See the example below for a better understanding.This parameter can be also an integer holding a filter constant. Then all values in the input array are filtered by this filter.
add_emptyAdd missing keys as NULL to the return value.