array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'function.filter-input-array.php', 1 => 'filter_input_array', ), 'up' => array ( 0 => 'ref.filter.php', 1 => 'Funciones de Filter', ), 'prev' => array ( 0 => 'function.filter-id.php', 1 => 'filter_id', ), 'next' => array ( 0 => 'function.filter-input.php', 1 => 'filter_input', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'es', 'path' => 'reference/filter/functions/filter-input-array.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
filter_input_array — Obtiene variables externas y opcionalmente las filtra
Esta función es útil para recuperar muchos valores sin necesidad de hacer repetidas llamadas a filter_input().
type
Una de las siguientes: INPUT_GET
, INPUT_POST
,
INPUT_COOKIE
, INPUT_SERVER
o
INPUT_ENV
.
definition
Un array definiendo los argumentos. Una clave válida será aquella que contiene
un string con el nombre de una variable y un valor
válido aquel que o bien es un tipo filter type
o un array especificando opcionalmente el filtro, flags y
opciones. Si el valor es un array, las claves válidas serán: filter
que especifica el tipo filter type,
flags
que define cualquier flag que deba aplicarse a los
filtros, y options
que establece cualquier opción que se deba
aplicar al filtro. Para entender mejor su funcionamiento, vea el ejemplo inferior.
Este parámetro puede ser también un entero que indique una constante de filtro. Entonces todos los valores en el array de entrada son filtrados por ese filtro.
add_empty
Añade claves faltantes como null
al valor devuelto.
En caso de éxito, un array con los valores de las variables que se han
pedido o false
en caso de fallo. Un valor del array puede ser false
si
el filtro falla o null
si la variable no está creada. O, si se usa el
flag FILTER_NULL_ON_FAILURE
y la variable no está
definida retorna false
y null
si el filtro falla.
Ejemplo #1 Un ejemplo con filter_input_array()
<?php
error_reporting(E_ALL | E_STRICT);
/* Los datos vienen realmente por POST
$_POST = array(
'id_producto' => 'libgd<script>',
'componente' => '10',
'version' => '2.0.33',
'test_escalar' => array('2', '23', '10', '12'),
'test_array' => '2',
);
*/
$args = array(
'id_producto' => FILTER_SANITIZE_ENCODED,
'componente' => array('filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_ARRAY,
'options' => array('min_range' => 1, 'max_range' => 10)
),
'version' => FILTER_SANITIZE_ENCODED,
'no_existe' => FILTER_VALIDATE_INT,
'test_escalar' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
),
'test_array' => array(
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_ARRAY,
)
);
$mis_entradas = filter_input_array(INPUT_POST, $args);
var_dump($mis_entradas);
echo "\n";
?>
El resultado del ejemplo sería:
array(6) { ["id_producto"]=> array(1) { [0]=> string(17) "libgd%3Cscript%3E" } ["componente"]=> array(1) { [0]=> int(10) } ["version"]=> array(1) { [0]=> string(6) "2.0.33" } ["no_existe"]=> NULL ["test_escalar"]=> bool(false) ["test_array"]=> array(1) { [0]=> int(2) } }
Versión | Descripción |
---|---|
5.4.0 |
Se añadió el parámetro add_empty .
|
Nota:
No existe la clave
REQUEST_TIME
en la matrizINPUT_SERVER
porque este valor se inserta posteriormente en $_SERVER.