Filter Input with array key

Asked

Viewed 34 times

0

I am receiving data from a form, and has a field that is comes in array from $_POST that is so:

Array
(
    [image_ids] => Array
        (
            [0] => 831
            [1] => 789
        )
)

And I want to take the amount by filter_input in this way:

$images = filter_input(INPUT_POST, 'image_ids');

and I can’t, does anyone have any idea how I take these values?

NOTE: the image variable returns False when I give var_dump

  • 1

    Why can’t you? Make a mistake? What is the final value of $images?

  • It returns false

  • Have you tried with the filter FILTER_REQUIRE_ARRAY?

  • No, I’ll test now that you’ve spoken

  • @Andersoncarloswoss put so and still came as false:

  • filter_input(INPUT_POST, 'image_ids', FILTER_REQUIRE_ARRAY)

Show 1 more comment

1 answer

0

I put this code and it worked:

$filters = array(
        'image_ids' => array(
             'filter' => FILTER_VALIDATE_INT,
             'flags' => FILTER_REQUIRE_ARRAY
        )
);
$images = filter_input_array(INPUT_POST, $filters);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.