note 116068 deleted from function.filter-input-array by salathe
| From: | salathe@php.net | Date: | Fri, 07 Nov 2014 11:16:13 +0000 |
| Subject: | note 116068 deleted from function.filter-input-array by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-200832@lists.php.net to get a copy of this message | ||
Note Submitter: tbrix13 at uzitech dot com
----
This function is for adding defaults if value is not found.
code:
<?php
//url: http://example.com?this=1&that=2
function filter_values($values, $type = INPUT_GET, $args = FILTER_SANITIZE_STRING){
$inputs = filter_input_array($type, $args);
foreach($values as $id => $default){
if(isset($inputs[$id])){
$values[$id] = $inputs[$id];
}
}
return $values;
}
var_dump(filter_values(array(
"test" => "default1",
"this" => "default2",
"that" => "default3",
)));
?>
output:
array(3) {
["test"]=>
string(1) "1"
["this"]=>
string(8) "default2"
["that"]=>
string(1) "2"
}