POST Variable Array and filter_input POST Variable Array and filter_input php php

POST Variable Array and filter_input


FILTER_REQUIRE_ARRAY will return false if the POST variable contains a scalar value. If you're unsure or just intend on the POST variable accepting both scalar and array values, use FILTER_FORCE_ARRAY instead, which will treat any input as an array, essentially casting scalar values accordingly.

$data = filter_input(INPUT_POST, 'data', FILTER_DEFAULT, FILTER_FORCE_ARRAY);


I have used FormData in javascript and post the fields with jquery ajax.The way I receive all these field is:

$arrFields = array('field1','field2','field2','field3', 'field4','field5');foreach($arrFields as $field){   $params[$field] = filter_input(INPUT_POST, $field, FILTER_DEFAULT);}var_dump($params);

Then I will get all the data into an array which I can pass on...