Is it possible to combine PHP's filter_input() filter flags with AND/OR?

PHPServer Side ProgrammingProgramming

Yes, it is possible to combine filter_input() with AND/OR in PHP. This can be done by looping over the POST fields−

$value = filter_input(INPUT_POST, 'field', FILTER_DEFAULT, is_array($_POST['field']) ? FILTER_REQUIRE_ARRAY : NULL);

An equivalent for the same user for each loop has been shown below−

$memory = array();
//looping through all posted values
foreach($_POST as $key => $value) {
   //applying a filter for the array
   if(is_array($value)) {
      $ memory [$key] = filter_input(INPUT_POST, $key, {filters for array});
   else {
      $ memory [$key] = filter_input(INPUT_POST, $key, {filters for scalar});
Updated on 27-Dec-2019 09:19:05