filter_var_array() function in PHP


The filter_var_array() function is used to filter multiple variables.

Syntax

filter_var_array(arrayname, parameters)

Parameters

  • arrayname − An array to filter the data.

  • parameters − It specifies an array of filter arguments.

Return

The filter_var_array() function returns an array of values of the requested variables on success or false on failure.

Example

Live Demo

<?php
   $arr = Array (
      "stname" => "Jack",
      "stmarks" => "95",
      "stemail" => "jack@abcde.com",
   ); 
   $filters = array (
      "stname" => array (
         "filter"=>FILTER_CALLBACK,
         "flags"=>FILTER_FORCE_ARRAY,
         "options"=>"ucwords"
      ),
      "stmarks" => array (
         "filter"=>FILTER_VALIDATE_INT,
         "options"=>array (
            "min_range"=>1,
            "max_range"=>100
         )
      ),
      "stemail"=> FILTER_VALIDATE_EMAIL,
   );
   print_r(filter_var_array($arr, $filters));
?>

The following is the output.

Array
(
   [stname] => Jack
   [stmarks] => 95
   [stemail] => jack@abcde.com
)

Updated on: 30-Jul-2019

410 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements