- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
FILTER_VALIDATE_INT constant in PHP
The FILTER_VALIDATE_INT constant validates value as integer.
Options and flags
min_range − The minimum integer value
max_range − The maximum integer value
FILTER_FLAG_ALLOW_OCTAL − Allows octal number values
FILTER_FLAG_ALLOW_HEX − Allows hexadecimal number values
Return
The FILTER_VALIDATE_INT constant does not return anything.
Example
<?php $int = 110; $var = 3.5; var_dump(filter_var($var, FILTER_VALIDATE_FLOAT)); if (filter_var($int, FILTER_VALIDATE_INT)) { echo("Integer Variable"); } else { echo("Not an Integer Variable"); } ?>
Output
The following is the output.
float(3.5) Integer Variable
Let us see another example.
Example
<?php $int = 5; $min = 1; $max = 20; if (filter_var($int, FILTER_VALIDATE_INT, array("options" => array("min_range"=>$min, "max_range"=>$max))) === false) { echo("Range not accepted!"); } else { echo("Accepted range!"); } ?>
Output
Here is the output.
Accepted range!
Advertisements