CKTIS / PHP
filter_var()
Aplica um filtro ao valor indicado.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
filter_var(mixed $value, int $filter = FILTER_DEFAULT, array|int $options = 0): mixedAplica um filtro ao valor indicado. O filtro predefinido FILTER_UNSAFE_RAW não valida. A validação de inteiros pode devolver 0, distinguível de false por comparação estrita. Os limites de intervalo podem rejeitar um inteiro bem formado.
Assinatura
filter_var(mixed $value, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed
Saída do exemplo
[0,false,"not a number"]
Exemplos
<?php
$options=["options"=>["min_range"=>0,"max_range"=>4]];
echo json_encode([filter_var("0",FILTER_VALIDATE_INT,$options),filter_var("5",FILTER_VALIDATE_INT,$options),filter_var("not a number")]);
Resultado
[0,false,"not a number"]