Here we will learn how to filter multiple variable using the filter_var_array() function.It returns an array of values for all the requested variables else it will return FALSE if failed.
Example
$abcd = array
(
"firstname" => "ravi",
"lastname" => "kumar",
"age" => "36",
"email" => "ravi@yopmail.com",
);
$filter_all = array
(
"firstname" => array
(
"filter"=>FILTER_CALLBACK,
"flags"=>FILTER_FORCE_ARRAY,
"options"=>"ucwords"
),
"lastname" => array
(
"filter"=>FILTER_CALLBACK,
"flags"=>FILTER_FORCE_ARRAY,
"options"=>"ucwords"
),
"age" => array
(
"filter"=>FILTER_VALIDATE_INT,
"options"=>array
(
"min_range"=>1,
"max_range"=>100
)
),
"email"=> FILTER_VALIDATE_EMAIL,
);
echo '<pre>'; print_r(filter_var_array($abcd, $filter_all));
OUTPUT:
Array
(
[firstname] => Ravi
[lastname] => Kumar
[age] => 36
[email] => ravi@yopmail.com
)
0 Comment(s)