note 116068 added to function.filter-input-array
| From: | tbrix13 at uzitech dot com | Date: | Wed, 05 Nov 2014 18:38:58 +0000 |
| Subject: | note 116068 added to function.filter-input-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200792@lists.php.net to get a copy of this message | ||
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"
}
----
Server IP: 72.52.91.14
Probable Submitter: 67.138.198.106
----
Manual Page -- http://php.net/manual/en/function.filter-input-array.php
Edit -- https://master.php.net/note/edit/116068
Del: integrated -- https://master.php.net/note/delete/116068/integrated
Del: useless -- https://master.php.net/note/delete/116068/useless
Del: bad code -- https://master.php.net/note/delete/116068/bad+code
Del: spam -- https://master.php.net/note/delete/116068/spam
Del: non-english -- https://master.php.net/note/delete/116068/non-english
Del: in docs -- https://master.php.net/note/delete/116068/in+docs
Del: other reasons-- https://master.php.net/note/delete/116068
Reject -- https://master.php.net/note/reject/116068
Search -- https://master.php.net/manage/user-notes.php