Filter multiple variables in PHP
Description
The following code shows how to filter multiple variables.
Example
//from w w w . j a v a 2 s . co m
<?php
$arr = array(
"name" => "CSS",
"age" => "41",
"email" => "j@example.com",
);
$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));
?>
The code above generates the following result.