How to validate value is Interger in Php?
This function checks whether a variable is of type integer or not.
1. Code:
<?php
function checkValueIsInterger($var){
return filter_var($var, FILTER_VALIDATE_INT);
}
var_dump(checkValueIsInterger(1));
echo "<br>";
var_dump(checkValueIsInterger('a'));
?>
2. Example:
Input:
input: 1 input: 1.2
Output:
output: true output: false