Latest web development tutorials

PHP filter_var_array () function

PHP Filter Reference Complete PHP Filter Reference

Definition and Usage

filter_var_array () function to get multiple variables, and filtered.

This function is useful filter plurality of values, without calling filter_var ().

If successful, the return value of the request places an array variable. If it fails, it returns FALSE.

grammar

filter_var_array(array, args)

参数 描述
array 必需。规定带有字符串键名的数组,包含要过滤的数据。
args 可选。规定过滤器参数数组。合法的数组键名是变量名,合法的值是过滤器 ID,或者规定过滤器、标志以及选项的数组。

该参数也可以是一个单一的过滤器 ID,如果是这样,输入数组中的所有值由指定过滤器进行过滤。

过滤器 ID 可以是 ID 名称(比如 FILTER_VALIDATE_EMAIL)或 ID 号(比如 274)。


Tips and Notes

Tip: See complete PHP Filter Reference view can be used in conjunction with the function of the filter.


Examples

<?php
$arr = array
(
"name" => "peter griffin",
"age" => "41",
"email" => "[email protected]",
);

$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_var_array($arr, $filters));
?>

Output code is as follows:

Array
(
[name] => Peter Griffin
[age] => 41
[email] => [email protected]
)


PHP Filter Reference Complete PHP Filter Reference