在PHP中发布差异

时间:2018-05-04 14:35:10

标签: php html

我正在使用一些代码从html表单中获取输入值,我想知道使用之间的区别:

filter_input(INPUT_POST, 'residence');

代替:$_POST['residence']

对于某些代码,我需要读取数据数组(复选框选项),$ _POST方法似乎可以完成工作而不是filter_input。

谢谢!

1 个答案:

答案 0 :(得分:0)

如果$ _POST包含数组值:

<?php
$_POST  = array(
    'var' => array('more', 'than', 'one', 'values')
);
?>

你应该使用FILTER_REQUIRE_ARRAY选项:

<?php
var_dump(filter_input(INPUT_POST, 'var', FILTER_DEFAULT , FILTER_REQUIRE_ARRAY));
?>

否则返回false。

(来自:https://secure.php.net/manual/en/function.filter-input.php