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

filter_input_array() function in PHP

PHPz
Release: 2023-09-23 17:18:01
forward
1305 people have browsed it

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)
Copy after login

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));
?>
Copy after login

The following is the output.

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

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template