Change language

PHP Filter_input_array () function

| |
Syntax:
mixed filter_input_array ($type_of_data, $definition, $add_empty_parameter)
Parameters:This function takes three parameters as above and described below:
  • type_of_data:This is a required parameter. It contains the type of data input to be checked. Available options:
    • INPUT_GET
    • INPUT_POST
    • INPUT_COOKIE
    • INPUT_SERVER
    • INPUT_ENV
  • definition:this is an optional parameter. It defines an array of arguments or filter parameters. A valid array key as a variable name and a valid value as a filter name or identifier, or an array specifying the filter, flags, and parameters. This parameter can also be a single filter name / ID, like filter_input(), then all values ​​in the input array are filtered by the specified filter.
  • add_empty_parameter:this is an optional parameter. This is a boolean parameter. It adds missing keys as NULL to the return value when it is set to True. The default is True.
Returned value:Returns an array containing the values ​​of the variables on success and on failure, returns False. If the input array denoted by the type is not filled, the function returns NULL, if the FILTER_NULL_ON_FAILURE flag is not specified, otherwise it returns False. For other failures, False is returned.The following programs illustrate the filter_input_array() function in PHP:Program 1: $filters = array ( "name" = > array ( "filter" = > FILTER_CALLBACK, " flags " = > FILTER_FORCE_ARRAY, "options" = > "ucwords" ), "age" = > array ( "filter" = > FILTER_VALIDATE_INT, "options" = > array ( " min_range " = > 1, "max_range" = > 120 ) ), "email" = > FILTER_VALIDATE_EMAIL, ); print_r (filter_input_array (INPUT_GET, $filters ));  
?>
Output: Note:This example may not work as expected in the online IDE because it doesn’t support passing parameters in a GET or POST method. So, try running it on some PHP host server or localhost and passing parameter values ​​using GET or POST method.Program 2:
Data received by POST method:
$_POST = array (’product_id’ = >’ 234 < A > ’,’ component’ = > array (’10’),’ version’ = > ’< 2.8.9’,’ array2’ = > array (’45’,’ 1’), ’scalar_data’ = >’ 2’,);

// PHP program for using the filter_input_array() function error_reporting (E_ALL | E_STRICT); $args = array ( ’id’ = > FILTER_SANITIZE_ENCODED, ’ array1’ = > array ( ’filter’ = > FILTER_VALIDATE_INT, ’flags’ = > FILTER_REQUIRE_ARRAY, ’options’ = > array ( ’min_range’ = > 1, ’max_range’ = > 10 ) ), ’version’ = > FILTER_SANITIZE_ENCODED, ’noparameter’ = > FILTER_VALIDATE_INT, ’scalar_data’ = > array ( ’filter’ = > FILTER_VALIDATE_INT, ’flags’  = > FILTER_REQUIRE_SCALAR, ), ’array2’ = > array ( ’filter’ = > FILTER_VALIDATE_INT, ’flags’  = > FILTER_REQUIRE_ARRAY, ) ); $allinputs = filter_input_array (INPUT_GET, $args ); var_dump ( $allinputs ); echo "" ;  
?>
Output: Note.This example may not work as expected in the online IDE because it doesn’t support passing parameters in a GET or POST method. So, try running it on some PHP host server or localhost and passing parameter values ​​using GET or POST method.Links: http://php.net/manual/en/function.filter-input-array.php

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically