filter_var_array

(PHP 5 >= 5.2.0, PHP 7)

filter_var_array锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷夜锟斤拷锟斤拷锟斤拷锟�

说锟斤拷

filter_var_array ( array $data [, mixed $definition [, bool $add_empty = true ]] ) : mixed

锟斤拷锟斤拷要锟截革拷锟斤拷锟斤拷 filter_var() 锟斤拷锟杰伙拷取锟斤拷锟斤拷锟斤拷锟斤拷锟�

锟斤拷锟斤拷

data

锟斤拷锟介,锟斤拷为锟街凤拷锟斤拷锟斤拷值为锟斤拷锟斤拷锟剿碉拷锟斤拷锟捷★拷

definition

一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷椤R伙拷锟斤拷锟叫э拷募锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟�string锟斤拷一锟斤拷锟斤拷效锟斤拷值要么锟斤拷一锟斤拷filter type锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷array 指锟斤拷锟剿癸拷锟斤拷锟斤拷锟斤拷锟斤拷示锟斤拷选锟筋。锟斤拷锟街碉拷锟揭伙拷锟斤拷锟斤拷椋拷锟矫达拷锟斤拷锟斤拷锟叫э拷募锟斤拷锟斤拷锟斤拷锟� filter锟斤拷 锟斤拷锟斤拷指锟斤拷 filter type锟斤拷flags 锟斤拷锟斤拷指锟斤拷锟轿猴拷锟斤拷要锟斤拷锟节癸拷锟斤拷锟斤拷锟侥憋拷示锟斤拷锟斤拷锟斤拷 options 锟斤拷锟斤拷指锟斤拷锟轿猴拷锟斤拷要锟斤拷锟节癸拷锟斤拷锟斤拷锟斤拷选锟筋。 锟轿匡拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷玫锟斤拷锟斤拷锟斤拷锟剿碉拷锟斤拷锟�

锟斤拷锟斤拷锟斤拷锟揭诧拷锟斤拷锟斤拷锟揭伙拷锟�filter constant锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷么锟斤拷锟斤拷锟叫碉拷锟斤拷锟斤拷值锟斤拷锟结被锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷恕锟�

add_empty

锟节凤拷锟斤拷值锟斤拷锟斤拷锟� NULL 锟斤拷为锟斤拷锟斤拷锟节的硷拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟斤拷晒锟斤拷蚍祷锟揭伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟介,锟斤拷锟竭碉拷失锟斤拷时锟斤拷锟斤拷 FALSE 锟斤拷 一锟斤拷锟斤拷锟斤拷锟街碉拷锟斤拷锟斤拷锟斤拷失锟斤拷锟斤拷为 FALSE 锟斤拷锟斤拷锟斤拷为 NULL 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷诘幕锟斤拷锟�

锟斤拷锟斤拷

Example #1 一锟斤拷 filter_var_array() 锟斤拷锟斤拷锟斤拷

<?php
error_reporting
(E_ALL E_STRICT);
$data = array(
    
'product_id'    => 'libgd<script>',
    
'component'     => '10',
    
'versions'      => '2.0.33',
    
'testscalar'    => array('2''23''10''12'),
    
'testarray'     => '2',
);

$args = array(
    
'product_id'   => FILTER_SANITIZE_ENCODED,
    
'component'    => array('filter'    => FILTER_VALIDATE_INT,
                            
'flags'     => FILTER_FORCE_ARRAY
                            
'options'   => array('min_range' => 1'max_range' => 10)
                           ),
    
'versions'     => FILTER_SANITIZE_ENCODED,
    
'doesnotexist' => FILTER_VALIDATE_INT,
    
'testscalar'   => array(
                            
'filter' => FILTER_VALIDATE_INT,
                            
'flags'  => FILTER_REQUIRE_SCALAR,
                           ),
    
'testarray'    => array(
                            
'filter' => FILTER_VALIDATE_INT,
                            
'flags'  => FILTER_FORCE_ARRAY,
                           )

);

$myinputs filter_var_array($data$args);

var_dump($myinputs);
echo 
"\n";
?>

锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�

array(6) {
  ["product_id"]=>
  string(17) "libgd%3Cscript%3E"
  ["component"]=>
  array(1) {
    [0]=>
    int(10)
  }
  ["versions"]=>
  string(6) "2.0.33"
  ["doesnotexist"]=>
  NULL
  ["testscalar"]=>
  bool(false)
  ["testarray"]=>
  array(1) {
    [0]=>
    int(2)
  }
}

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
5.4.0 锟斤拷锟� add_empty 锟斤拷锟斤拷锟斤拷

锟轿硷拷

  • filter_input_array() - 锟斤拷取一系锟斤拷锟解部锟斤拷锟斤拷锟斤拷锟斤拷锟揭匡拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
  • filter_var() - 使锟斤拷锟截讹拷锟侥癸拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷
  • filter_input() - 通锟斤拷锟斤拷锟狡伙拷取锟截讹拷锟斤拷锟解部锟斤拷锟斤拷锟斤拷锟斤拷锟揭匡拷锟斤拷通锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
  • Types of filters