Syntax:mixed filter_input_array ($type_of_data, $definition, $add_empty_parameter)
Parameters:This function takes three parameters as above and described below:
- type_of_data:This is a required parameter. It contains the type of data input to be checked. Available options:
- INPUT_GET
- INPUT_POST
- INPUT_COOKIE
- INPUT_SERVER
- INPUT_ENV
- definition:this is an optional parameter. It defines an array of arguments or filter parameters. A valid array key as a variable name and a valid value as a filter name or identifier, or an array specifying the filter, flags, and parameters. This parameter can also be a single filter name / ID, like filter_input(), then all values in the input array are filtered by the specified filter.
- add_empty_parameter:this is an optional parameter. This is a boolean parameter. It adds missing keys as NULL to the return value when it is set to True. The default is True.
Returned value:Returns an array containing the values of the variables on success and on failure, returns False. If the input array denoted by the type is not filled, the function returns NULL, if the FILTER_NULL_ON_FAILURE flag is not specified, otherwise it returns False. For other failures, False is returned.The following programs illustrate the filter_input_array() function in PHP:
Program 1:
$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_input_array (INPUT_GET,
$filters
));
?>
Output: Note:This example may not work as expected in the online IDE because it doesn’t support passing parameters in a GET or POST method. So, try running it on some PHP host server or localhost and passing parameter values using GET or POST method.Program 2:
Data received by POST method: $_POST = array (’product_id’ = >’ 234 < A > ’,’ component’ = > array (’10’),’ version’ = > ’< 2.8.9’,’ array2’ = > array (’45’,’ 1’), ’scalar_data’ = >’ 2’,);
// PHP program for using the filter_input_array() function
error_reporting
(E_ALL | E_STRICT);
$args
=
array
(
’id’
= > FILTER_SANITIZE_ENCODED,
’ array1’
= >
array
(
’filter’
= > FILTER_VALIDATE_INT,
’flags’
= > FILTER_REQUIRE_ARRAY,
’options’
= >
array
(
’min_range’
= > 1,
’max_range’
= > 10
)
),
’version’
= > FILTER_SANITIZE_ENCODED,
’noparameter’
= > FILTER_VALIDATE_INT,
’scalar_data’
= >
array
(
’filter’
= > FILTER_VALIDATE_INT,
’flags’
= > FILTER_REQUIRE_SCALAR,
),
’array2’
= >
array
(
’filter’
= > FILTER_VALIDATE_INT,
’flags’
= > FILTER_REQUIRE_ARRAY,
)
);
$allinputs
= filter_input_array (INPUT_GET,
$args
);
var_dump (
$allinputs
);
echo
""
;
?>
Output: Note.This example may not work as expected in the online IDE because it doesn’t support passing parameters in a GET or POST method. So, try running it on some PHP host server or localhost and passing parameter values using GET or POST method.Links: http://php.net/manual/en/function.filter-input-array.php
SO 1 data error