Home  >  Article  >  Backend Development  >  filter_input_array() function in PHP

filter_input_array() function in PHP

PHPz
PHPzforward
2023-09-23 17:17:021178browse

filter_input_array() function in PHP

filter_input_array() function gets the names of external variables and optionally filters them.

grammar

filter_input_array(type, arraydefine, add_empty)

parameter

  • type - There are five types of input to check, namely INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.

  • arraydefine - It specifies an array of filter parameters. This is optional.

  • add_empty - If True, missing keys will be added to the return value as NULL.

return

filter_input_array() function returns an array containing variable values ​​on success and false on failure.

Example

The following is an example of using the filter_input_array() function to filter the POST variables stname (student name), stmarks (student score), stemail (student email)

<?php
   $filters = array (
      "stname" => array (
         "filter"=>FILTER_CALLBACK,
         "flags"=>FILTER_FORCE_ARRAY,
         "options"=>"ucwords"
      ),
      "stmarks" => array (
         "filter"=>FILTER_VALIDATE_INT,
         "options"=>array (
            "min_range"=>1,
            "max_range"=>100
         )
      ),
      "stemail"=> FILTER_VALIDATE_EMAIL,
   );
   print_r(filter_input_array(INPUT_POST, $filters));
?>

The following is the output.

Array (
   [stname] => Jack
   [stmarks] => 95
   [stemail] => jack@abcde.com
)

The above is the detailed content of filter_input_array() function in PHP. 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