CKTIS / PHP
filter_input_array()
Filtruje wiele oryginalnych pól SAPI wspólnym filtrem lub mapą reguł.
Wersja: PHP 8.4; repository runtime, production runtime not attested
Składnia
filter_input_array(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|nullFiltruje wiele oryginalnych pól SAPI wspólnym filtrem lub mapą reguł. Gdy źródło istnieje, add_empty dodaje brakujące żądane klucze z null. W CLI bez źródła GET cały wynik to null nawet po ręcznej zmianie $_GET. Przy istniejącym źródle i FILTER_NULL_ON_FAILURE brakujący klucz z add_empty=true pozostaje null. Pojedyncze filter_input z tą flagą zwraca dla niego false.
Sygnatura
filter_input_array(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null
Wynik przykładu
[{"qty":6,"memo":null},false]
Przykłady
<?php
if (PHP_SAPI==="cgi-fcgi") {
$rules=["qty"=>FILTER_VALIDATE_INT,"memo"=>["filter"=>FILTER_VALIDATE_INT,"flags"=>FILTER_NULL_ON_FAILURE]];
echo json_encode([filter_input_array(INPUT_GET,$rules,true),filter_input(INPUT_GET,"memo",FILTER_VALIDATE_INT,FILTER_NULL_ON_FAILURE)]);
exit;
}
$env=["REDIRECT_STATUS"=>"1","SCRIPT_FILENAME"=>__FILE__,"REQUEST_METHOD"=>"GET","QUERY_STRING"=>"qty=6"];
$proc=proc_open([PHP_BINDIR."/php-cgi"],[1=>["pipe","w"]],$pipes,null,$env);
$response=stream_get_contents($pipes[1]); fclose($pipes[1]); proc_close($proc);
[$headers,$body]=preg_split("/\\r?\\n\\r?\\n/",$response,2);
echo $body;
Wynik
[{"qty":6,"memo":null},false]