2

I tried to use filter_input to load my POST value into a variable:

$tmp = filter_input(INPUT_POST, "p_member");    // fails

Output:

bool(false)

I also tried $tmp = filter_input_array(INPUT_POST, "p_member"); // fails

Output:

bool(false)

But this works:

$tmp = (array)@$_POST['p_member'];

Output:

enter image description here

3
  • Your answer is always here php.net/manual/en/function.filter-input.php Commented Oct 1, 2019 at 16:52
  • 1
    To add on to @Azael's comment, use the FILTER_REQUIRE_ARRAY option Commented Oct 1, 2019 at 16:54
  • @Das_Geek, I tried $tmp2 = filter_input(INPUT_POST, "p_member", FILTER_REQUIRE_ARRAY); result -> bool(false) Commented Oct 1, 2019 at 16:57

1 Answer 1

2

here is an answer based on link

If your $_POST contains an array value:

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

you should use FILTER_DEFAULT AND FILTER_REQUIRE_ARRAY option:

var_dump(filter_input(INPUT_POST, 'var', FILTER_DEFAULT , FILTER_REQUIRE_ARRAY));

Otherwise it returns false.

Sign up to request clarification or add additional context in comments.

1 Comment

Thx, we have to use both FILTER_DEFAULT , FILTER_REQUIRE_ARRAY to make it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.