<?php
$data = [
'product_id' => 'libgd<script>',
'component' => '10',
'versions' => '2.0.33',
'testscalar' => ['2', '23', '10', '12'],
'testarray' => '2',
];
$filters = [
'product_id' => FILTER_SANITIZE_ENCODED,
'component' => [
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FORCE_ARRAY,
'options' => [
'min_range' => 1,
'max_range' => 10,
],
],
'versions' => [
'filter' => FILTER_SANITIZE_ENCODED
],
'testscalar' => [
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
],
'testarray' => [
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FORCE_ARRAY,
],
'doesnotexist' => FILTER_VALIDATE_INT,
];
var_dump(filter_var_array($data, $filters));
?>
array(6) {
["product_id"]=>
string(17) "libgd%3Cscript%3E"
["component"]=>
array(1) {
[0]=>
int(10)
}
["versions"]=>
string(6) "2.0.33"
["testscalar"]=>
bool(false)
["testarray"]=>
array(1) {
[0]=>
int(2)
}
["doesnotexist"]=>
NULL
}