Checking if a variable is an integer in PHP
In PHP, you can use the is_int()
function to check if a variable is an integer.
Example:
<?php
$x = 5;
if (is_int($x)) {
echo "x is an integer";
} else {
echo "x is not an integer";
}
Watch a video course
Learn object oriented PHP
You can also use is_integer()
which is an alias of is_int()
.
<?php
$x = 5;
if (is_integer($x)) {
echo "x is an integer";
} else {
echo "x is not an integer";
}