How to use filter var array in PHP

This article describe about filter_var_array() Function in PHP.
  • 3130

filter_var_array() Function

This function gets multiple variable and optionally filters them.

Without calling filter_var() keep on (over and over)  filter_var_array() function filter the several input variable. It is main importance of this function.

On success return array of data and FALSE on failure.

Syntax

filter_var_array ( array, args)

Example

<html>
<body>
<?php
error_reporting(E_ALL | E_STRICT);
$data = array(
'product_id' => 'libgd<script>',
'component' => '10',
'versions' => '2.0.33',
'testscalar' => array('2', '23', '10', '12'),
'testarray' => '2',
);
$args = array(
'product_id' => FILTER_SANITIZE_ENCODED,
'component' => array('filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FORCE_ARRAY,
'options' => array('min_range' => 1, 'max_range' => 10)
),
'versions' => FILTER_SANITIZE_ENCODED,
'doesnotexist' => FILTER_VALIDATE_INT,
'testscalar' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
),
'testarray' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FORCE_ARRAY,
)
);
$myinputs = filter_var_array($data, $args);
var_dump($myinputs);
echo "\n";
?>
</body>
</html>

Output

pic7.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.