Use the filter_var_array() function to filter multiple variables at once.
<?php $data = array( ‘fullname’ => ‘Peter Griffin’, ‘age’ => ’41’, ’email’ => ‘[email protected]’, ); $mydata = filter_var_array($data); var_dump($mydata); ?> |
The result of the code should be:
array(3) { [“fullname”]=> string(13) “Peter Griffin” [“age”]=> string(2) “41” [“email”]=> string(17) “[email protected]” } |
The filter_var_array() function handles multiple variables and can optionally filter them. This function is useful for filtering several values at once, avoiding multiple calls to filter_var().
Tip: Consult the PHP Filter Reference for available filters that can be used with this function.
filter_var_array(data_array, args, add_empty) |
Parameter |
Description |
data_array |
Mandatory. Specifies an array with string keys that contains the data to be filtered. |
args |
Optional. Specifies an array of filter arguments. The array keys should be variable names, and the values can be either a filter ID or an array detailing the filter, flags, and options. Alternatively, a single filter ID can be provided, in which case all values in the input array will be filtered using that filter. The filter ID can be a name (e.g., |
add_empty |
Optional. A boolean value. Setting it to |
Return Value: |
An array of the requested variable values if successful, or |
PHP Version: |
5.2+ |
PHP Changelog: |
In PHP 5.4, the |