gettype()
` function, which returns a string indicating the data type of the variable. To check if a variable is an integer, you can use the `is_int()
` function, which returns `true
` if the variable is an integer and `false
` otherwise.<?php
$num = 10;
if (is_int($num)) {
echo "The variable is an integer.";
} else {
echo "The variable is not an integer.";
}
?>
The variable is an integer.
$num
` is assigned the integer value `10
`. The `if
` statement checks if `$num
` is an integer using the `is_int()
` function. $num
` is an integer, then the code inside the `if
` block is executed, which simply prints the message "The variable is an integer." Otherwise, the code inside the `else
` block is executed, which prints the message "The variable is not an integer."is_int()
` function to check if a variable is an integer in PHP.