PHP filter_var_array() Function
Example
Use the filter_var_array() function to get multiple variables:
<?php
$data = array(
'fullname' => 'Peter Griffin',
'age' => '41',
'email' => 'peter@example.com',
);
$mydata = filter_var_array($data);
var_dump($mydata);
?>
The output of the code should be:
array(3) {
["fullname"]=>
string(13) "Peter Griffin"
["age"]=>
string(2) "41"
["email"]=>
string(17)
"peter@example.com"
}
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() many times.
Tip: Check the PHP Filter Reference for possible filters to use with this function.
Syntax
filter_var_array(data_array, args, add_empty)
Parameter Values
Parameter | Description |
---|---|
data_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 option. 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) |
add_empty | Optional. A Boolean value. TRUE adds missing keys as NULL to the return value. Default value is TRUE |
Technical Details
Return Value: | An array of values of the requested variables on success, FALSE on failure |
---|---|
PHP Version: | 5.2+ |
PHP Changelog: | PHP 5.4 - The add_empty parameter was added |
❮ Complete PHP Filter Reference