CKTIS / PHP
filter_input_array()
Filtert mehrere ursprüngliche SAPI-Felder mit einem Filter oder einer Regel je Feld.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
filter_input_array(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|nullFiltert mehrere ursprüngliche SAPI-Felder mit einem Filter oder einer Regel je Feld. Bei vorhandener Quelle ergänzt add_empty fehlende angeforderte Schlüssel mit null. Im CLI ohne GET-Quelle ist das Gesamtergebnis selbst nach Änderung von $_GET null. Bei vorhandener Quelle und FILTER_NULL_ON_FAILURE bleibt ein fehlender Schlüssel mit add_empty=true null. Das einzelne filter_input liefert dafür false.
Signatur
filter_input_array(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null
Ausgabe des Beispiels
[{"qty":6,"memo":null},false]
Beispiele
<?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;
Ergebnis
[{"qty":6,"memo":null},false]