Home  >  Article  >  Backend Development  >  Can I use PHP's filter_input() filter flag with AND/OR?

Can I use PHP's filter_input() filter flag with AND/OR?

WBOY
WBOYforward
2023-09-04 15:01:08548browse

Can I use PHPs filter_input() filter flag with AND/OR?

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

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

The equivalent for the same user for each loop would look like this -

$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});
   }
}

The above is the detailed content of Can I use PHP's filter_input() filter flag with AND/OR?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete